제출 #285674

#제출 시각아이디문제언어결과실행 시간메모리
285674Saboon곤돌라 (IOI14_gondola)C++14
100 / 100
37 ms3196 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9+9; int valid(int n, int inputSeq[]){ vector<int> A; for (int i = 0; i < n; i++) A.push_back(inputSeq[i]); sort(A.begin(),A.end()); for (int i = 1; i < n; i++) if (A[i] == A[i-1]) return 0; int idx = min_element(inputSeq, inputSeq+n) - inputSeq; if (inputSeq[idx] > n) return true; int cnt = 0; for (int i = idx; i < n; i++){ if (inputSeq[i] <= n and inputSeq[idx]+cnt != inputSeq[i]) return false; cnt ++; } for (int i = 0; i < idx; i++){ if (inputSeq[i] <= n and inputSeq[idx]+cnt != inputSeq[i]) return false; cnt ++; } return true; } int p[maxn]; int replacement(int n, int gondolaSeq[], int replacementSeq[]){ for (int i = 0; i < n; i++) p[i] = i+1; for (int i = 0; i < n; i++){ if (gondolaSeq[i] > n) continue; int cnt = 0; for (int j = i; j < n; j++) p[j] = (gondolaSeq[i]+cnt-1)%n+1, cnt++; for (int j = 0; j < i; j++) p[j] = (gondolaSeq[i]+cnt-1)%n+1, cnt++; break; } vector<pair<int,int>> A; for (int i = 0; i < n; i++) A.push_back({gondolaSeq[i],i}); sort(A.begin(),A.end()); int l = 0, now = n+1; for (auto it : A){ int i = it.second; if (gondolaSeq[i] <= n) continue; while (now <= gondolaSeq[i]) replacementSeq[l++] = p[i], p[i] = now++; } return l; } int power(int a, int b){ if (b == 0) return 1; int ret = power(a,b/2); ret = 1LL*ret*ret%mod; if (b&1) ret = 1LL*ret*a%mod; return ret; } int countReplacement(int n, int inputSeq[]){ if (!valid(n, inputSeq)) return 0; int Z = 1; if (*min_element(inputSeq,inputSeq+n) > n) Z = n; vector<pair<int,int>> A; for (int i = 0; i < n; i++) if (inputSeq[i] > n) A.push_back({inputSeq[i],i}); sort(A.begin(),A.end()); int now = n, m = A.size(); int mx = *max_element(inputSeq,inputSeq+n); for (int i = 0; i < A.size(); i++){ int diff = A[i].first-now; Z = 1LL*Z*power(m,diff-1)%mod; m --, now = A[i].first; } return Z; }

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  for (int i = 0; i < A.size(); i++){
      |                  ~~^~~~~~~~~~
gondola.cpp:84:6: warning: unused variable 'mx' [-Wunused-variable]
   84 |  int mx = *max_element(inputSeq,inputSeq+n);
      |      ^~
#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...