Submission #302162

#TimeUsernameProblemLanguageResultExecution timeMemory
302162JPN20Roller Coaster Railroad (IOI16_railroad)C++17
34 / 100
265 ms17436 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; long long N; long long S[1 << 18], T[1 << 18]; long long dp[1 << 16][16]; bool calc(int stt, int goa) { vector<int> vec; for (int i = 0; i < N; i++) { if (i == stt) continue; int pos1 = lower_bound(T, T + N, S[i] + 1) - T; if (goa < pos1) pos1--; vec.push_back(pos1); } sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++) { if (vec[i] <= i) return false; } return true; } long long solve_subtask3() { // SORTS vector<pair<long long, long long>> vec; for (int i = 0; i < N; i++) vec.push_back(make_pair(T[i], S[i])); sort(vec.begin(), vec.end()); for (int i = 0; i < N; i++) T[i] = vec[i].first; for (int i = 0; i < N; i++) S[i] = vec[i].second; // PRCLC vector<pair<int, int>> vecs; for (int i = 0; i < N; i++) vecs.push_back(make_pair(S[i], i)); sort(vecs.begin(), vecs.end()); // FINAL int u1 = vecs[0].second, u2 = vecs[1].second; int v1 = 0, v2 = 1; bool flag = false; if (u1 != v1 && calc(u1, v1) == true) flag = true; if (u1 != v2 && calc(u1, v2) == true) flag = true; if (u2 != v1 && calc(u2, v1) == true) flag = true; if (flag == true) return 0; return 1000000007LL; } long long solve_subtask2() { // PRCLC for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < N; j++) dp[i][j] = (1LL << 60); } for (int i = 0; i < N; i++) dp[1 << i][i] = 0; // CALC for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < N; j++) { if (dp[i][j] == (1LL << 60)) continue; for (int k = 0; k < N; k++) { if ((i / (1 << k)) % 2 == 1) continue; long long cost = max(0LL, T[j] - S[k]); dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + cost); } } } // FINAL long long Answer = (1LL << 60); for (int i = 0; i < N; i++) Answer = min(Answer, dp[(1 << N) - 1][i]); return Answer; } long long plan_roller_coaster(vector<int> s, vector<int> t) { N = s.size(); for (int i = 0; i < N; i++) S[i] = s[i]; for (int i = 0; i < N; i++) T[i] = t[i]; if (N <= 16) return solve_subtask2(); return solve_subtask3(); }

Compilation message (stderr)

railroad.cpp: In function 'bool calc(int, int)':
railroad.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < vec.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...