답안 #763532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763532 2023-06-22T12:18:46 Z Polar_Bear_2007 Xylophone (JOI18_xylophone) C++14
100 / 100
95 ms 496 KB
#ifdef MINHDEPTRAI
 
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/bits/stdc++.h"  
#include <chrono>
#define __gcd(a, b) gcd(a, b)
using namespace std ::chrono;
#else 
#include <bits/stdc++.h>
#include <xylophone.h>
#endif
 
using namespace std;
#define foru(i, a, b) for(int i = a; i <= b; ++i)
#define ford(i, a, b) for(int i = a; i >= b; --i)
#define IOS ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp(a, b) make_pair(a, b)
#define endl '\n'
const int maxN = 2e6 + 5;
const int mod = 998244353;
const long long inf = 1e17;
 
vector<int> number, triple;
 
int dau[maxN], ans[maxN], counting[maxN];

// int query(int a, int b){
//     cout << "? " <<  a << " " << b << endl;
//     int val;
//     cin >> val;
//     return val;
// }
// void answer(int i, int a){
//     cout << a << " ";
// }

void solve(int N){
    
    if(N == 2){
        answer(1, 1);
        answer(2, 2);
        return;
    }
    
    int i = 1, j = 2;
    while(j <= N){
        number.push_back(query(i, j));
        i++;
        j++;
    }
    int k = 3;
    i = 1;
    while(k <= N){
        triple.push_back(query(i, k));
        i++;
        k++;
    }
 
    dau[0] = 1;
    for(int j = 0; j <= N - 3; j++){
        if(triple[j] == number[j + 1] + number[j]){
            dau[j + 1] = dau[j];
        }
        else{
            dau[j + 1] = -dau[j];   
        }
    }
    int min_pos = 0, min_val = maxN, sum = 0, pos_five = N + 1;

    for(int j = 0; j <= N - 2; j++){
        sum += dau[j] * number[j];

        if(min_val > sum){
            min_val = sum;
            min_pos = j + 1; 
        }
    }
    if(min_pos == 1) min_pos = 0;

    ans[min_pos] = 1;
    ford(j, min_pos - 1, 0){
        ans[j] = ans[j + 1] +  number[j] * (- dau[j]);
        if(ans[j] == N) pos_five = j;
    }

    foru(j, min_pos + 1, N - 1){
        ans[j] = ans[j - 1] + number[j - 1] * dau[j - 1];
        if(ans[j] == N) pos_five = j;
    }

    if(min_pos > pos_five){
        min_pos = 0, min_val = maxN, sum = 0;
        foru(i, 0, N - 2) dau[i] = -dau[i];



        for(int j = 0; j <= N - 2; j++){
            sum += dau[j] * number[j];

            if(min_val > sum){
                min_val = sum;
                min_pos = j + 1; 
            }
        }
        if(min_pos == 1) min_pos = 0;
    
        
        ans[min_pos] = 1;
        ford(j, min_pos - 1, 0){
            ans[j] = ans[j + 1] +  number[j] * (- dau[j]);
            //cout << number[j] << " " << - dau[j] << endl;
        }

        foru(j, min_pos + 1, N - 1){
            ans[j] = ans[j - 1] + number[j - 1] *  dau[j - 1];
        }
    }
    int sum_check = 0;
    foru(i, 0, N - 1){
        sum_check += i + 1;
        sum_check -= ans[i];
    }
    if(sum_check != 0) foru(i, 0, N - 1) answer(i + 1, ans[i] + 1);
    else foru(i, 0, N - 1) answer(i + 1, ans[i]);

}
// signed main(){
//     int n;
//     cin >> n;
//     solve(n);
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 312 KB Output is correct
17 Correct 7 ms 308 KB Output is correct
18 Correct 13 ms 312 KB Output is correct
19 Correct 15 ms 304 KB Output is correct
20 Correct 16 ms 312 KB Output is correct
21 Correct 15 ms 316 KB Output is correct
22 Correct 13 ms 320 KB Output is correct
23 Correct 17 ms 316 KB Output is correct
24 Correct 13 ms 316 KB Output is correct
25 Correct 10 ms 220 KB Output is correct
26 Correct 13 ms 316 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 17 ms 448 KB Output is correct
29 Correct 16 ms 208 KB Output is correct
30 Correct 12 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 312 KB Output is correct
17 Correct 7 ms 308 KB Output is correct
18 Correct 13 ms 312 KB Output is correct
19 Correct 15 ms 304 KB Output is correct
20 Correct 16 ms 312 KB Output is correct
21 Correct 15 ms 316 KB Output is correct
22 Correct 13 ms 320 KB Output is correct
23 Correct 17 ms 316 KB Output is correct
24 Correct 13 ms 316 KB Output is correct
25 Correct 10 ms 220 KB Output is correct
26 Correct 13 ms 316 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 17 ms 448 KB Output is correct
29 Correct 16 ms 208 KB Output is correct
30 Correct 12 ms 308 KB Output is correct
31 Correct 25 ms 320 KB Output is correct
32 Correct 23 ms 304 KB Output is correct
33 Correct 59 ms 348 KB Output is correct
34 Correct 36 ms 488 KB Output is correct
35 Correct 81 ms 348 KB Output is correct
36 Correct 85 ms 316 KB Output is correct
37 Correct 61 ms 448 KB Output is correct
38 Correct 70 ms 444 KB Output is correct
39 Correct 65 ms 448 KB Output is correct
40 Correct 59 ms 452 KB Output is correct
41 Correct 83 ms 352 KB Output is correct
42 Correct 63 ms 368 KB Output is correct
43 Correct 59 ms 332 KB Output is correct
44 Correct 46 ms 352 KB Output is correct
45 Correct 84 ms 436 KB Output is correct
46 Correct 82 ms 496 KB Output is correct
47 Correct 64 ms 372 KB Output is correct
48 Correct 95 ms 344 KB Output is correct
49 Correct 90 ms 348 KB Output is correct
50 Correct 70 ms 348 KB Output is correct
51 Correct 63 ms 348 KB Output is correct
52 Correct 40 ms 480 KB Output is correct
53 Correct 74 ms 344 KB Output is correct
54 Correct 70 ms 476 KB Output is correct
55 Correct 67 ms 328 KB Output is correct
56 Correct 81 ms 440 KB Output is correct
57 Correct 86 ms 456 KB Output is correct
58 Correct 60 ms 448 KB Output is correct
59 Correct 57 ms 328 KB Output is correct
60 Correct 84 ms 348 KB Output is correct