제출 #1024426

#제출 시각아이디문제언어결과실행 시간메모리
1024426socpite마상시합 토너먼트 (IOI12_tournament)C++17
100 / 100
46 ms20252 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5+5; const int INF = 1e9; vector<int> g[maxn]; int FW[maxn]; int id[maxn], r[maxn], mn[maxn], A[maxn]; void add(int idx, int val){ for(idx; idx < maxn; idx += idx&(-idx))FW[idx] += val; } int find_kth(int k){ int pos = 0; for(int i = 17; i >= 0; i--){ if((pos^(1<<i)) >= maxn)continue; if(k - FW[pos^(1<<i)] >= 0){ pos^=(1<<i); k -= FW[pos]; } } return pos+1; } int ans = -1, pos, tdfs = 0; void pre_dfs(int x){ mn[x] = INF; if(g[x].empty())tdfs++; for(int i = 0; i < g[x].size(); i++){ pre_dfs(g[x][i]); mn[x] = min(mn[x], mn[g[x][i]]); if(i + 1 < g[x].size())mn[x] = min(mn[x], A[r[g[x][i]]]); } r[x] = tdfs; } void dfs(int x, int R, int dep, int dep_valid){ if(mn[x] > R && dep_valid == -1)dep_valid = dep; if(g[x].empty() && dep - dep_valid > ans){ ans = dep - dep_valid; pos = x; } for(auto v: g[x])dfs(v, R, dep+1, dep_valid); } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { memset(FW, 0, sizeof(FW)); for(int i = 0; i < maxn; i++)g[i].clear(); for(int i = 1; i <= N; i++){ id[i] = i; add(i, 1); } for(int i = 1; i < N; i++){ A[i] = K[i-1]; A[i] = N - A[i]; } R = N - R; for(int i = 0; i < C; i++){ N++; for(int _ = 0; _ < E[i] - S[i]; _++){ int pos = find_kth(S[i]); g[N].push_back(id[pos]); add(pos, -1); id[pos] = 0; } int pos = find_kth(S[i]); g[N].push_back(id[pos]); id[pos] = N; } pre_dfs(N); dfs(N, R, 0, -1); return pos - 1; }

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

tournament.cpp: In function 'void add(int, int)':
tournament.cpp:12:6: warning: statement has no effect [-Wunused-value]
   12 |  for(idx; idx < maxn; idx += idx&(-idx))FW[idx] += val;
      |      ^~~
tournament.cpp: In function 'void pre_dfs(int)':
tournament.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < g[x].size(); i++){
      |                 ~~^~~~~~~~~~~~~
tournament.cpp:35:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   if(i + 1 < g[x].size())mn[x] = min(mn[x], A[r[g[x][i]]]);
      |      ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...