제출 #490769

#제출 시각아이디문제언어결과실행 시간메모리
490769RainbowbunnySwap (BOI16_swap)C++17
100 / 100
48 ms5956 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 5; const int INF = 1e9; int n; int A[MAXN], state[MAXN]; int Findup(int id) { int ans = INF; while(id > 0) { // cout << id << "o" << endl; // cout << A[id] << endl; if(state[id] != 1) { ans = min(ans, A[id]); } if(state[id] == 0) { return ans; } if(id & 1) { if(state[id - 1] == 1) { return min(ans, A[id - 1]); } if(state[id - 1] == -1) { ans = min(ans, A[id - 1]); } } id >>= 1; } } void Move(int id, int val) { while(id) { // cout << id << "H" << endl; if(A[id] == val) { state[id] = 0; return; } if(id & 1) { if(A[id - 1] == val) { state[id - 1] = 1; state[id] = 1; break; } else { state[id - 1] = 0; } } state[id] = 1; id >>= 1; } } int main() { // freopen("Input.txt", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> A[i]; } for(int i = n + 1; i <= 2 * n + 1; i++) { A[i] = INF; } for(int i = 1; i <= 2 * n; i++) { state[i] = -1; } state[1] = 0; for(int i = 1; i <= n; i++) { int v = Findup(i); int tmp = min({v, A[2 * i], A[2 * i + 1]}); if(tmp == v) { Move(i, v); state[2 * i] = 0; state[2 * i + 1] = 0; } else if(tmp == A[2 * i]) { state[2 * i] = 1; state[2 * i + 1] = 0; } else if(tmp == A[2 * i + 1]) { state[2 * i + 1] = 1; } // for(int j = 2; j <= n; j++) // { // cout << state[j] << ' '; // } // cout << '\n'; cout << tmp << ' '; } cout << '\n'; }

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

swap.cpp: In function 'int Findup(int)':
swap.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
   38 | }
      | ^
#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...