제출 #788823

#제출 시각아이디문제언어결과실행 시간메모리
788823acatmeowmeow곤돌라 (IOI14_gondola)C++11
55 / 100
30 ms4648 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]) { ios::sync_with_stdio(false); cin.tie(nullptr); set<int> st; for (int i = 0; i < n; i++) { if (st.count(inputSeq[i])) return 0; st.insert(inputSeq[i]); } int lowest = 1e9, pos = 1e9; for (int i = 0; i < n; i++) { if (lowest > inputSeq[i]) { lowest = inputSeq[i], pos = i; } } if (lowest > n) return 1; for (int i = pos, cnt = lowest, len = 1; len <= n; i = (i + 1) % n, len++, cnt = cnt % n + 1) { if (inputSeq[i] > n) continue; if (cnt != inputSeq[i]) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { if (*max_element(gondolaSeq, gondolaSeq + n) == n) return 0; int lowest = 1e9, pos = 1e9; for (int i = 0; i < n; i++) { if (gondolaSeq[i] < lowest) { lowest = gondolaSeq[i]; pos = i; } } vector<pair<int, int>> arr; if (lowest > n) { for (int i = 0; i < n; i++) arr.push_back({gondolaSeq[i], i + 1}); sort(arr.begin(), arr.end()); } else { for (int i = pos, len = 1, cnt = lowest; len <= n; i = (i + 1) % n, len++, cnt = cnt % n + 1) { if (gondolaSeq[i] <= n) continue; arr.push_back({gondolaSeq[i], cnt}); } sort(arr.begin(), arr.end()); } int index = 0, cur = n + 1; for (auto&x : arr) { int v = x.first, pos = x.second; replacementSeq[index++] = pos; for (int i = cur; i < v; i++) replacementSeq[index++] = i; cur = v + 1; } return index; } //---------------------- int countReplacement(int n, int inputSeq[]) { return -3; } /*int gondolaSequence[100001]; int replacementSequence[250001]; signed main() { int i, n, tag; int nr; //assert(scanf("%d", &tag)==1); //assert(scanf("%d", &n)==1); cin >> tag >> n; for(i=0;i< n;i++) cin >> gondolaSequence[i]; //assert( scanf("%d", &gondolaSequence[i]) ==1); switch (tag){ case 1: case 2: case 3: printf("%d\n", valid(n, gondolaSequence)); break; case 4: case 5: case 6: nr = replacement(n, gondolaSequence, replacementSequence); printf("%d ", nr); if (nr > 0) { for (i=0; i<nr-1; i++) printf("%d ", replacementSequence[i]); printf("%d\n", replacementSequence[nr-1]); } else printf("\n"); break; case 7: case 8: case 9: case 10: printf("%d\n", countReplacement(n, gondolaSequence)); break; } return 0; }*/
#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...