답안 #322271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322271 2020-11-14T11:04:05 Z dolphingarlic Swap (BOI16_swap) C++14
컴파일 오류
0 ms 0 KB
map<pi,int> bes;
int n, p[MX];
 
int get(int ind, int y) {
    if (bes.count({ind,y})) return bes[{ind,y}];
    if (2*ind > n) return ind;
    if (2*ind+1 > n) {
        if (y > p[2*ind]) return 2*ind;
        return ind;
    }
    if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
    if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
    int mn = min(y,p[2*ind]);
    if (get(2*ind,mn) < get(2*ind+1,mn)) {
        if (mn == y) return bes[{ind,y}] = get(2*ind,y);
        return bes[{ind,y}] = get(2*ind+1,y);
    } else {
        if (mn == y) return bes[{ind,y}] = get(2*ind+1,y);
        return bes[{ind,y}] = get(2*ind,y);
    }
}
 
void solve(int ind) {
    if (2*ind > n) return;
    if (2*ind+1 > n) {
        if (p[ind] > p[2*ind]) swap(p[ind],p[2*ind]);
        return;
    }
    
    if (p[ind] < min(p[2*ind],p[2*ind+1])) {
        
    } else if (p[2*ind] < min(p[ind],p[2*ind+1])) {
        swap(p[2*ind],p[ind]);
    } else {
        int mn = min(p[ind],p[2*ind]), mx = max(p[ind],p[2*ind]);
        
        p[ind] = p[2*ind+1];
        if (get(2*ind,mn) < get(2*ind+1,mn)) {
            p[2*ind] = mn, p[2*ind+1] = mx;
        } else {
            p[2*ind] = mx, p[2*ind+1] = mn;    
        }
    }
    solve(ind+1);
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    FOR(i,1,n+1) cin >> p[i];
    solve(1);
    FOR(i,1,n+1) cout << p[i] << " ";
}

Compilation message

swap.cpp:1:1: error: 'map' does not name a type
    1 | map<pi,int> bes;
      | ^~~
swap.cpp:2:10: error: 'MX' was not declared in this scope
    2 | int n, p[MX];
      |          ^~
swap.cpp: In function 'int get(int, int)':
swap.cpp:5:9: error: 'bes' was not declared in this scope
    5 |     if (bes.count({ind,y})) return bes[{ind,y}];
      |         ^~~
swap.cpp:8:17: error: 'p' was not declared in this scope
    8 |         if (y > p[2*ind]) return 2*ind;
      |                 ^
swap.cpp:11:17: error: 'p' was not declared in this scope
   11 |     if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
      |                 ^
swap.cpp:11:13: error: 'min' was not declared in this scope
   11 |     if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
      |             ^~~
swap.cpp:11:46: error: 'bes' was not declared in this scope
   11 |     if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
      |                                              ^~~
swap.cpp:12:9: error: 'p' was not declared in this scope
   12 |     if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
      |         ^
swap.cpp:12:20: error: 'min' was not declared in this scope
   12 |     if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
      |                    ^~~
swap.cpp:12:46: error: 'bes' was not declared in this scope
   12 |     if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
      |                                              ^~~
swap.cpp:13:20: error: 'p' was not declared in this scope
   13 |     int mn = min(y,p[2*ind]);
      |                    ^
swap.cpp:13:14: error: 'min' was not declared in this scope; did you mean 'mn'?
   13 |     int mn = min(y,p[2*ind]);
      |              ^~~
      |              mn
swap.cpp:15:29: error: 'bes' was not declared in this scope
   15 |         if (mn == y) return bes[{ind,y}] = get(2*ind,y);
      |                             ^~~
swap.cpp:16:16: error: 'bes' was not declared in this scope
   16 |         return bes[{ind,y}] = get(2*ind+1,y);
      |                ^~~
swap.cpp:18:29: error: 'bes' was not declared in this scope
   18 |         if (mn == y) return bes[{ind,y}] = get(2*ind+1,y);
      |                             ^~~
swap.cpp:19:16: error: 'bes' was not declared in this scope
   19 |         return bes[{ind,y}] = get(2*ind,y);
      |                ^~~
swap.cpp: In function 'void solve(int)':
swap.cpp:26:13: error: 'p' was not declared in this scope
   26 |         if (p[ind] > p[2*ind]) swap(p[ind],p[2*ind]);
      |             ^
swap.cpp:26:32: error: 'swap' was not declared in this scope
   26 |         if (p[ind] > p[2*ind]) swap(p[ind],p[2*ind]);
      |                                ^~~~
swap.cpp:30:9: error: 'p' was not declared in this scope
   30 |     if (p[ind] < min(p[2*ind],p[2*ind+1])) {
      |         ^
swap.cpp:30:18: error: 'min' was not declared in this scope
   30 |     if (p[ind] < min(p[2*ind],p[2*ind+1])) {
      |                  ^~~
swap.cpp:33:9: error: 'swap' was not declared in this scope
   33 |         swap(p[2*ind],p[ind]);
      |         ^~~~
swap.cpp:39:41: error: 'mx' was not declared in this scope; did you mean 'mn'?
   39 |             p[2*ind] = mn, p[2*ind+1] = mx;
      |                                         ^~
      |                                         mn
swap.cpp:41:24: error: 'mx' was not declared in this scope; did you mean 'mn'?
   41 |             p[2*ind] = mx, p[2*ind+1] = mn;
      |                        ^~
      |                        mn
swap.cpp: In function 'int main()':
swap.cpp:48:5: error: 'ios_base' has not been declared
   48 |     ios_base::sync_with_stdio(0); cin.tie(0);
      |     ^~~~~~~~
swap.cpp:48:35: error: 'cin' was not declared in this scope
   48 |     ios_base::sync_with_stdio(0); cin.tie(0);
      |                                   ^~~
swap.cpp:50:9: error: 'i' was not declared in this scope
   50 |     FOR(i,1,n+1) cin >> p[i];
      |         ^
swap.cpp:50:5: error: 'FOR' was not declared in this scope
   50 |     FOR(i,1,n+1) cin >> p[i];
      |     ^~~