Submission #3287299
Source Code Expand
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef long double ld; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds; int a[222222]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; vector<int> vec; ll ans = 0; for(int i=0;i<n;i++) { if(vec.empty()||a[i]>=vec.back()) { vec.pb(a[i]); continue; } int mn = int(1e9); int aft = i-1; int x = 0; for(int j=i-1;j>=-1;j--) { int val = i - 1 - j + max(0, (j>=0?vec[j]:-int(1e9)) - a[i]); if(val<mn) { mn=val; aft=j; x = max(0, (j>=0?vec[j]:-int(1e9)) - a[i]); } } vi nw; ans += mn; for(int j=0;j<=aft;j++) nw.pb(vec[j]); nw.pb(a[i]+x); for(int j=aft+1;j<i;j++) nw.pb(vec[j]); vec=nw; } cout<<ans<<'\n'; }
Submission Info
Submission Time | |
---|---|
Task | B - Increment and Swap |
User | zscoder |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1112 Byte |
Status | TLE |
Exec Time | 2103 ms |
Memory | 2432 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1500 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | TLE | 2103 ms | 1532 KB |
001.txt | TLE | 2103 ms | 1584 KB |
002.txt | TLE | 2103 ms | 1524 KB |
003.txt | TLE | 2103 ms | 1632 KB |
004.txt | TLE | 2103 ms | 1632 KB |
005.txt | TLE | 2103 ms | 1632 KB |
006.txt | TLE | 2103 ms | 1632 KB |
007.txt | TLE | 2103 ms | 1568 KB |
008.txt | TLE | 2103 ms | 1644 KB |
009.txt | TLE | 2103 ms | 1520 KB |
010.txt | TLE | 2103 ms | 1504 KB |
011.txt | TLE | 2103 ms | 1648 KB |
012.txt | TLE | 2103 ms | 1656 KB |
013.txt | TLE | 2103 ms | 1504 KB |
014.txt | TLE | 2103 ms | 1504 KB |
015.txt | TLE | 2103 ms | 1660 KB |
016.txt | TLE | 2103 ms | 1548 KB |
017.txt | TLE | 2103 ms | 1580 KB |
018.txt | TLE | 2103 ms | 1548 KB |
019.txt | TLE | 2103 ms | 1668 KB |
020.txt | TLE | 2103 ms | 1492 KB |
021.txt | AC | 1008 ms | 748 KB |
022.txt | TLE | 2103 ms | 1580 KB |
023.txt | TLE | 2103 ms | 1208 KB |
024.txt | TLE | 2103 ms | 896 KB |
025.txt | TLE | 2103 ms | 1208 KB |
026.txt | AC | 1258 ms | 804 KB |
027.txt | TLE | 2103 ms | 1444 KB |
028.txt | TLE | 2103 ms | 1140 KB |
029.txt | TLE | 2103 ms | 1124 KB |
030.txt | TLE | 2103 ms | 1136 KB |
031.txt | TLE | 2103 ms | 1448 KB |
032.txt | TLE | 2103 ms | 1232 KB |
033.txt | TLE | 2103 ms | 1236 KB |
034.txt | TLE | 2103 ms | 1496 KB |
035.txt | TLE | 2103 ms | 960 KB |
036.txt | TLE | 2103 ms | 1572 KB |
037.txt | TLE | 2103 ms | 1240 KB |
038.txt | TLE | 2103 ms | 1000 KB |
039.txt | TLE | 2103 ms | 1168 KB |
040.txt | TLE | 2103 ms | 1108 KB |
041.txt | TLE | 2103 ms | 1416 KB |
042.txt | AC | 19 ms | 2168 KB |
043.txt | TLE | 2103 ms | 1880 KB |
044.txt | TLE | 2103 ms | 1540 KB |
045.txt | AC | 1 ms | 256 KB |
046.txt | TLE | 2103 ms | 1644 KB |
047.txt | TLE | 2103 ms | 1624 KB |
048.txt | TLE | 2103 ms | 1712 KB |
049.txt | TLE | 2103 ms | 1656 KB |
050.txt | TLE | 2103 ms | 1832 KB |
051.txt | TLE | 2103 ms | 1632 KB |
052.txt | TLE | 2103 ms | 1632 KB |
053.txt | TLE | 2103 ms | 1500 KB |
054.txt | TLE | 2103 ms | 1540 KB |
055.txt | TLE | 2103 ms | 2432 KB |
056.txt | TLE | 2103 ms | 1700 KB |
057.txt | TLE | 2103 ms | 1684 KB |
058.txt | TLE | 2103 ms | 1804 KB |
059.txt | TLE | 2103 ms | 1644 KB |
060.txt | TLE | 2103 ms | 1624 KB |
061.txt | TLE | 2103 ms | 1628 KB |
062.txt | AC | 19 ms | 2168 KB |
063.txt | TLE | 2103 ms | 1880 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |