Submission #1021347

#TimeUsernameProblemLanguageResultExecution timeMemory
1021347IssaRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
136 ms12072 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int inf = 1e9 + 100; const ll INF = 1e18 + 100; const int maxn = 2e5 + 100; int n; ll dp[1<<16][16]; int a[maxn]; int b[maxn]; vector<int> s; int pref[maxn]; int p[maxn]; int get(int v){ if(p[v] == v) return v; return p[v] = get(p[v]); } void join(int a, int b){ p[get(a)] = get(b); } long long plan_roller_coaster(std::vector<int> s, std::vector<int> t){ n = s.size(); for(int i = 0; i < n; i++){ a[i] = s[i]; b[i] = t[i]; } if(0 && n <= 16){ for(int x = 0; x < (1<<n); x++){ fill(dp[x], dp[x] + n, INF); if(!x) continue; if(__builtin_popcount(x) == 1){ for(int i = 0; i < n; i++){ if(x & (1<<i)) dp[x][i] = 0; } } else{ for(int i = 0; i < n; i++){ if(x & (1<<i)){ int y = x ^ (1<<i); for(int j = 0; j < n; j++){ if(y & (1<<j)){ dp[x][i] = min(dp[x][i], dp[y][j] + max(0, t[j] - s[i])); } } } } } } return *min_element(dp[(1<<n)-1], dp[(1<<n)-1] + n); } else{ for(int i = 0; i < n; i++){ s.push_back(a[i]); s.push_back(b[i]); } sort(s.begin(), s.end()); s.resize(unique(s.begin(), s.end()) - s.begin()); for(int i = 1; i <= s.size(); i++){ p[i] = i; } for(int i = 0; i < n; i++){ a[i] = lower_bound(s.begin(), s.end(), a[i]) - s.begin() + 1; b[i] = lower_bound(s.begin(), s.end(), b[i]) - s.begin() + 1; join(a[i], b[i]); } a[n] = s.size(); b[n] = 1; join(s.size(), 1); for(int i = 0; i <= n; i++){ pref[a[i]]++; pref[b[i]]--; } for(int i = 1; i <= s.size(); i++){ pref[i] += pref[i-1]; if(pref[i] > 0) return 1; if(pref[i] < 0){ join(i, i + 1); } } // for(int i = 1; i < s.size(); i++){ // if(get(i) != get(i+1)) return 1; // } return 0; } }

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int i = 1; i <= s.size(); i++){
      |                  ~~^~~~~~~~~~~
railroad.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i = 1; i <= s.size(); i++){
      |                  ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...