제출 #614776

#제출 시각아이디문제언어결과실행 시간메모리
614776cheissmart곤돌라 (IOI14_gondola)C++14
75 / 100
40 ms4808 KiB
#include "gondola.h" #include <bits/stdc++.h> #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, M = 1e9 + 9; int valid(int n, int a[]) { int he = -1; set<int> s; for(int i = 0; i < n; i++) { if(s.count(a[i])) return 0; s.insert(a[i]); } for(int i = 0; i < n; i++) if(a[i] <= n) { int be = (i - a[i] + n) % n; if(he != -1 && he != be) return 0; he = be; } return 1; } int replacement(int n, int a[], int b[]) { assert(valid(n, a)); int sz = 0, mx = 0; map<int, int> mp; int pos = -1; for(int i = 0; i < n; i++) { mx = max(mx, a[i]); if(a[i] >= n) { mp[a[i]] = i; } else { pos = i; } } if(pos == -1) { for(int i = 0; i < n; i++) a[i] = i + 1; } else { for(int i = pos + 1; i < n; i++) { a[i] = (a[pos] + i - pos + n - 1) % n + 1; } for(int i = 0; i < pos; i++) { a[i] = (a[pos] + i - pos + n - 1) % n + 1; } } for(int i = n + 1; i <= mx; i++) { if(mp.count(i)) { b[sz++] = a[mp[i]]; a[mp[i]] = i; } else { b[sz++] = a[mp[mx]]; a[mp[mx]] = i; } } return sz; } int qpow(int a, int b) { if(b == 0) return 1; ll t = qpow(a, b / 2); t = t * t % M; if(b & 1) t = t * a % M; return t; } int countReplacement(int n, int a[]) { if(!valid(n, a)) return 0; int mx = 0; vi aux; for(int i = 0; i < n; i++) { mx = max(mx, a[i]); if(a[i] > n) { aux.PB(a[i]); } } aux.PB(n); int ans = 1, cnt = 0; sort(ALL(aux), greater<int>()); for(int i = 0; i + 1 < SZ(aux); i++) { for(int j = aux[i] - 1; j > aux[i + 1]; j--) ans = 1LL * ans * (i + 1) % M; // ans = 1LL * ans * qpow(i + 1, aux[i] - aux[i + 1] - 1) % M; } if(SZ(aux) == n) ans = 1LL * ans * n % M; return ans; }

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

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:92:18: warning: unused variable 'cnt' [-Wunused-variable]
   92 |     int ans = 1, cnt = 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...