답안 #989236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989236 2024-05-27T19:27:19 Z user736482 Xylophone (JOI18_xylophone) C++17
100 / 100
72 ms 600 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

/*void answer(int a,int b){
    cout<<b<<" k ";
}
int query(int a,int b){
    vector<int>v={2,1,5,3,4};
    int min_=99999,max_=0;
    for(int i=a-1;i<b;i++){
        min_=min(min_,v[i]);
        max_=max(max_,v[i]);
    }
    return max_-min_;
}*/
void solve(int n){
    int tab1[n],tab2[n],ak,ak2,ak3;
    tab1[0]=0,tab2[0]=0;
    if(n==1){
        answer(1,1);
        return;
    }
    if(n==2){
        answer(1,1);
        answer(2,2);
        return;
    }
    ak2=query(1,2);
    tab1[1]=ak2;
    tab2[1]=-ak2;
    //cout<<tab1[0]<<" "<<tab2[0]<<"\n";
    //cout<<tab1[1]<<" "<<tab2[1]<<"\n";
    for(int i=2;i<n;i++){
        ak3=ak2;
        ak=query(i-1,i+1);
        ak2=query(i,i+1);
        if(tab1[i-1]>tab1[i-2]){
            tab1[i]=tab1[i-1]+ak2*((ak-ak3==ak2)*2-1);
        }
        else{
            tab1[i]=tab1[i-1]-ak2*((ak-ak3==ak2)*2-1);
        }
        if(tab2[i-1]>tab2[i-2]){
            //cout<<tab2[i-2]<<" "<<tab2[i-1]<<"   ";
            tab2[i]=tab2[i-1]+ak2*((ak-ak3==ak2)*2-1);
        }
        else{
            tab2[i]=tab2[i-1]-ak2*((ak-ak3==ak2)*2-1);
        }
        //cout<<tab1[i]<<" "<<tab2[i]<<"\n";
    }
    ak=99999;
    for(int i=0;i<n;i++){
        ak=min(ak,tab1[i]);
    }
    for(int i=0;i<n;i++){
        tab1[i]-=(ak-1);
    }
    for(int i=0;i<n;i++){
        if(tab1[i]==1){
            for(int j=0;j<n;j++){
                answer(j+1,tab1[j]);
            }
            return;
        }
        if(tab1[i]==n)
            break;
    }
    ak=99999;
    for(int i=0;i<n;i++){
        ak=min(ak,tab2[i]);
    }
    for(int i=0;i<n;i++){
        tab2[i]-=(ak-1);
    }
    for(int j=0;j<n;j++){
        answer(j+1,tab2[j]);
    }
}
//int main(){
//    solve(5);
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Correct 9 ms 344 KB Output is correct
25 Correct 10 ms 440 KB Output is correct
26 Correct 15 ms 344 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 11 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Correct 9 ms 344 KB Output is correct
25 Correct 10 ms 440 KB Output is correct
26 Correct 15 ms 344 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 11 ms 344 KB Output is correct
31 Correct 24 ms 428 KB Output is correct
32 Correct 33 ms 428 KB Output is correct
33 Correct 58 ms 592 KB Output is correct
34 Correct 56 ms 344 KB Output is correct
35 Correct 65 ms 344 KB Output is correct
36 Correct 50 ms 468 KB Output is correct
37 Correct 54 ms 344 KB Output is correct
38 Correct 39 ms 464 KB Output is correct
39 Correct 60 ms 460 KB Output is correct
40 Correct 43 ms 448 KB Output is correct
41 Correct 58 ms 448 KB Output is correct
42 Correct 66 ms 444 KB Output is correct
43 Correct 59 ms 448 KB Output is correct
44 Correct 56 ms 448 KB Output is correct
45 Correct 65 ms 444 KB Output is correct
46 Correct 59 ms 344 KB Output is correct
47 Correct 64 ms 448 KB Output is correct
48 Correct 72 ms 448 KB Output is correct
49 Correct 51 ms 448 KB Output is correct
50 Correct 55 ms 448 KB Output is correct
51 Correct 48 ms 444 KB Output is correct
52 Correct 30 ms 452 KB Output is correct
53 Correct 58 ms 448 KB Output is correct
54 Correct 72 ms 592 KB Output is correct
55 Correct 68 ms 448 KB Output is correct
56 Correct 52 ms 448 KB Output is correct
57 Correct 48 ms 344 KB Output is correct
58 Correct 51 ms 452 KB Output is correct
59 Correct 61 ms 592 KB Output is correct
60 Correct 58 ms 468 KB Output is correct