답안 #636250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636250 2022-08-28T15:29:39 Z Ronin13 Xylophone (JOI18_xylophone) C++14
100 / 100
107 ms 1084 KB
#include "xylophone.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;



void solve(int N) {
    int n = N;
    vector <int> last;
    last.pb(0);
    last.pb(query(1, 2));
    for(int i = 3; i <= n; i++){
        int x = query(i - 1, i);
        int y = query(i - 2, i);
        int l = last.back() / (abs(last.back()));
        if(y == x + abs(last.back())) last.pb(x * l);
        else last.pb(-x * l);
    }

    map<int, int> used;
    used[0] = true;
    int pref = 0;
    int ind;
    for(int i = 1; i < last.size(); i++){
        pref += last[i];
        if(used[pref - (n - 1)]){
            ind = i;
            break;
        }
        if(used[pref - (1 - n)]){
            ind = i;
            break;
        }
        used[pref] = true;
    }
    if(last[ind] < 0){
        for(int i = 0; i < last.size(); i++) last[i] *= (-1);
    }
   // answer(ind + 1, n);
    int a[n + 1];
    a[ind + 1] = n;
    for(int i = ind; i >= 0; i--){
        int x = last[i];
        a[i] = a[i + 1] - x;

    //    answer(i, a[i]);
    }
    for(int i = ind + 2; i <= n; i++){
        int x = last[i - 1];
        a[i] = a[i - 1] + x;
       // answer(i, a[i]);
    }

    for(int i = 1; i <= n; i++) answer(i, a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 1; i < last.size(); i++){
      |                    ~~^~~~~~~~~~~~~
xylophone.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int i = 0; i < last.size(); i++) last[i] *= (-1);
      |                        ~~^~~~~~~~~~~~~
xylophone.cpp:43:16: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |     if(last[ind] < 0){
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 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 308 KB Output is correct
12 Correct 3 ms 300 KB Output is correct
13 Correct 3 ms 296 KB Output is correct
14 Correct 3 ms 296 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 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 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 308 KB Output is correct
12 Correct 3 ms 300 KB Output is correct
13 Correct 3 ms 296 KB Output is correct
14 Correct 3 ms 296 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 9 ms 300 KB Output is correct
18 Correct 13 ms 328 KB Output is correct
19 Correct 17 ms 304 KB Output is correct
20 Correct 19 ms 308 KB Output is correct
21 Correct 21 ms 412 KB Output is correct
22 Correct 21 ms 328 KB Output is correct
23 Correct 19 ms 420 KB Output is correct
24 Correct 16 ms 416 KB Output is correct
25 Correct 20 ms 296 KB Output is correct
26 Correct 22 ms 304 KB Output is correct
27 Correct 19 ms 300 KB Output is correct
28 Correct 18 ms 288 KB Output is correct
29 Correct 18 ms 412 KB Output is correct
30 Correct 16 ms 300 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 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 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 308 KB Output is correct
12 Correct 3 ms 300 KB Output is correct
13 Correct 3 ms 296 KB Output is correct
14 Correct 3 ms 296 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 9 ms 300 KB Output is correct
18 Correct 13 ms 328 KB Output is correct
19 Correct 17 ms 304 KB Output is correct
20 Correct 19 ms 308 KB Output is correct
21 Correct 21 ms 412 KB Output is correct
22 Correct 21 ms 328 KB Output is correct
23 Correct 19 ms 420 KB Output is correct
24 Correct 16 ms 416 KB Output is correct
25 Correct 20 ms 296 KB Output is correct
26 Correct 22 ms 304 KB Output is correct
27 Correct 19 ms 300 KB Output is correct
28 Correct 18 ms 288 KB Output is correct
29 Correct 18 ms 412 KB Output is correct
30 Correct 16 ms 300 KB Output is correct
31 Correct 28 ms 552 KB Output is correct
32 Correct 54 ms 676 KB Output is correct
33 Correct 60 ms 672 KB Output is correct
34 Correct 90 ms 808 KB Output is correct
35 Correct 89 ms 960 KB Output is correct
36 Correct 98 ms 1060 KB Output is correct
37 Correct 87 ms 952 KB Output is correct
38 Correct 85 ms 296 KB Output is correct
39 Correct 78 ms 840 KB Output is correct
40 Correct 107 ms 688 KB Output is correct
41 Correct 80 ms 804 KB Output is correct
42 Correct 69 ms 928 KB Output is correct
43 Correct 105 ms 924 KB Output is correct
44 Correct 83 ms 328 KB Output is correct
45 Correct 94 ms 420 KB Output is correct
46 Correct 102 ms 952 KB Output is correct
47 Correct 96 ms 448 KB Output is correct
48 Correct 87 ms 692 KB Output is correct
49 Correct 90 ms 1084 KB Output is correct
50 Correct 97 ms 680 KB Output is correct
51 Correct 88 ms 828 KB Output is correct
52 Correct 87 ms 976 KB Output is correct
53 Correct 88 ms 688 KB Output is correct
54 Correct 86 ms 456 KB Output is correct
55 Correct 69 ms 436 KB Output is correct
56 Correct 107 ms 568 KB Output is correct
57 Correct 106 ms 552 KB Output is correct
58 Correct 94 ms 928 KB Output is correct
59 Correct 58 ms 588 KB Output is correct
60 Correct 100 ms 692 KB Output is correct