Submission #508857

#TimeUsernameProblemLanguageResultExecution timeMemory
508857tabrGondola (IOI14_gondola)C++17
55 / 100
35 ms4672 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif #include "gondola.h" int valid(int n, int s[]) { set<int> st; for (int i = 0; i < n; i++) { if (st.count(s[i])) { return 0; } st.emplace(s[i]); } int pos = -1; for (int i = 0; i < n; i++) { if (s[i] <= n) { pos = (i - s[i] + 1 + n) % n; break; } } for (int i = 0; i < n; i++) { if (s[i] <= n) { if (pos != (i - s[i] + 1 + n) % n) { return 0; } } } return 1; } int replacement(int n, int s[], int res[]) { int pos = -1; for (int i = 0; i < n; i++) { if (s[i] <= n) { pos = (i - s[i] + 1 + n) % n; } } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { return s[i] < s[j]; }); int id = 0; int lst = n; for (int i : order) { if (s[i] <= n) { continue; } int j = (i - pos + n) % n + 1; res[id++] = j; for (int x = lst + 2; x <= s[i]; x++) { res[id++] = x - 1; } lst = s[i]; } return id; } int countReplacement(int n, int s[]) { if (!valid(n, s)) { return 0; } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...