제출 #218868

#제출 시각아이디문제언어결과실행 시간메모리
218868Kenzo_1114곤돌라 (IOI14_gondola)C++17
90 / 100
27 ms3328 KiB
#include "gondola.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 100010; const long long int MOD = 1e9 + 9; int correct[MAXN], pos[3 * MAXN]; bool marc[3 * MAXN], all = false; void calc(int n, int seq[]) { int id = -1; for(int i = 0; i < n; i++) if(seq[i] <= n) { id = i; break; } if(id != -1) correct[id] = seq[id]; else id = 0, correct[id] = 1, all = true; for(int i = id + 1; i < n; i++) { correct[i] = correct[i - 1] + 1; if(correct[i] > n) correct[i] = 1; } for(int i = id - 1; i >= 0; i--) { correct[i] = correct[i + 1] - 1; if(correct[i] < 1) correct[i] = n; } } int valid(int n, int seq[]) { calc(n, seq); int ans = 1; for(int i = 0; i < n; i++) { if(seq[i] <= n && correct[i] != seq[i]) ans = 0; if(seq[i] > n && marc[seq[i]]) ans = 0; marc[seq[i]] = true; } for(int i = 0; i < 3 * MAXN; i++) marc[i] = false; return ans; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { calc(n, gondolaSeq); for(int i = 0; i < 3 * MAXN; i++) pos[i] = -1; int mx = n; for(int i = 0; i < n; i++) if(gondolaSeq[i] > n) pos[gondolaSeq[i]] = i, mx = max(mx, gondolaSeq[i]); for(int i = mx - 1; i > n; i--) if(pos[i] == -1) pos[i] = pos[i + 1]; int l = 0; for(int i = n + 1; i <= mx; i++) { replacementSeq[l] = correct[pos[i]]; correct[pos[i]] = i; l++; } return l; } long long int fe(long long int num, long long int exp) { if(exp == 0) return 1; if(exp == 1) return num; long long int aux = fe(num, exp / 2); aux *= aux, aux %= MOD; if(exp % 2) return (aux * num) % MOD; return aux % MOD; } int countReplacement(int n, int inputSeq[]) { if(!valid(n, inputSeq)) return 0; vector<long long int> v; for(int i = 0; i < n; i++) if(inputSeq[i] > n) v.push_back(inputSeq[i]); sort(v.begin(), v.end()); long long int ans = 1; long long int sz = v.size(), last = n; for(int i = 0; i < v.size(); i++) { // printf("num = %lld exp = %lld\n", sz, v[i] - 1- last); ans *= fe(sz, v[i] - 1 - last); ans %= MOD; last = v[i]; sz--; } if(all) ans *= n, ans %= MOD; return (int) ans; } /* 5 6 7 1 2 3 : 1 1 2 3 , 2 1 2 3, 3 1 2 3 2 3 1 : 2 3 1 3 1 2 : */ /* int N, SEQ[MAXN]; int main () { scanf("%d", &N); for(int i = 0; i < N; i++) scanf("%d", &SEQ[i]); printf("valid = %d\n", valid(N, SEQ)); printf("cont = %lld\n", countReplacement(N, SEQ)); } */

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

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:103:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.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...
#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...