# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444317 | 2021-07-13T15:18:53 Z | Kitonds | Palembang Bridges (APIO15_bridge) | C++14 | 288 ms | 14388 KB |
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define read(A) freopen((A + ".in").c_str(),"r",stdin) #define write(A) freopen((A + ".out").c_str(),"w",stdout) #define ll long long #define pb push_back #define ull unsigned long long #define int long long #define f first #define s second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, ii> iii; typedef vector<iii> viii; const int DFS_WHITE = 0; const int DFS_BLACK = 1; const int INF = 1e9 + 5; const int MAXN = 105 ; const int MOD = 1e9 + 7; void setIO(string filename = ""){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(filename.size() == 0) return; read(filename); write(filename); } struct person { int s, e; person(int s_, int e_){ this->s = s_, this->e = e_; } bool operator <(const person &y){ return s + e < y.s + y.e; } }; int n, k, m; multiset<int> upper, lower; int cur_low, cur_up; void in(int val){ int med = (!lower.empty()? *lower.rbegin(): INF); if (val > med){ upper.insert(val); cur_up += val; if (upper.size() > lower.size() + 1){ int tmp = *upper.begin(); lower.insert(tmp); upper.erase(upper.find(tmp)); cur_up -= tmp; cur_low += tmp; } } else{ lower.insert(val); cur_low += val; if (lower.size() > upper.size() + 1){ int tmp = *lower.rbegin(); upper.insert(tmp); lower.erase(lower.find(tmp)); cur_up += tmp; cur_low -= tmp; } } } void solve(){ cin>>m>>n; vector<person> A; int same = 0; for (int i=0; i<n; i++){ int a, b; char c, d; cin>>c>>a>>d>>b; if (c == d){ same += abs(a - b); } else{ A.pb({a, b}); } } // cout<<"A"; A.pb({0, 0}); sort(all(A)); vi pref(A.size(), 0); for (int i=1; i<A.size(); i++){ in(A[i].s); in(A[i].e); pref[i] = cur_up - cur_low; // cout<<cur_up<<" "<<cur_low<<" "<<*lower.rbegin()<<endl; // cout<<A[i].s<<" "<<A[i].e<<endl; } int ans = pref[A.size() - 1]; if(m == 2){ lower.clear(); upper.clear(); cur_low = cur_up = 0; for (int i=A.size()-1; i>0; i--){ in(A[i].s); in(A[i].e); ans = min(ans, cur_up - cur_low + pref[i - 1]); } } cout<<ans + same + A.size() - 1; } signed main() { setIO(); int test = 1; // cin>>test; while(test--){ solve(); if (test) cout<<endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 2 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 85 ms | 12812 KB | Output is correct |
13 | Correct | 144 ms | 14332 KB | Output is correct |
14 | Correct | 124 ms | 11960 KB | Output is correct |
15 | Correct | 72 ms | 8500 KB | Output is correct |
16 | Correct | 90 ms | 13624 KB | Output is correct |
17 | Correct | 120 ms | 14316 KB | Output is correct |
18 | Correct | 74 ms | 13880 KB | Output is correct |
19 | Correct | 115 ms | 14364 KB | Output is correct |
20 | Correct | 108 ms | 13888 KB | Output is correct |
21 | Correct | 117 ms | 14128 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 280 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 2 ms | 332 KB | Output is correct |
15 | Correct | 2 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 2 ms | 332 KB | Output is correct |
20 | Correct | 2 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 2 ms | 332 KB | Output is correct |
23 | Correct | 2 ms | 332 KB | Output is correct |
24 | Correct | 2 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 316 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 312 KB | Output is correct |
12 | Correct | 1 ms | 312 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 2 ms | 332 KB | Output is correct |
15 | Correct | 2 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 2 ms | 332 KB | Output is correct |
20 | Correct | 2 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 2 ms | 332 KB | Output is correct |
23 | Correct | 2 ms | 332 KB | Output is correct |
24 | Correct | 2 ms | 332 KB | Output is correct |
25 | Correct | 167 ms | 12784 KB | Output is correct |
26 | Correct | 239 ms | 13020 KB | Output is correct |
27 | Correct | 280 ms | 13760 KB | Output is correct |
28 | Correct | 280 ms | 14260 KB | Output is correct |
29 | Correct | 288 ms | 14388 KB | Output is correct |
30 | Correct | 107 ms | 7728 KB | Output is correct |
31 | Correct | 133 ms | 13628 KB | Output is correct |
32 | Correct | 187 ms | 14316 KB | Output is correct |
33 | Correct | 116 ms | 13880 KB | Output is correct |
34 | Correct | 185 ms | 14288 KB | Output is correct |
35 | Correct | 173 ms | 13876 KB | Output is correct |
36 | Correct | 177 ms | 14064 KB | Output is correct |
37 | Correct | 172 ms | 12920 KB | Output is correct |