Submission #996026

# Submission time Handle Problem Language Result Execution time Memory
996026 2024-06-10T07:25:05 Z toan2602 Xylophone (JOI18_xylophone) C++14
100 / 100
75 ms 956 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;

int n, p1[5005], p2[5005], a[5005];

bool mark[50005];

void ANSWER(vector<int> &v) {
    for (int i = 0; i < v.size(); i++) answer(i+1,v[i]);
}

void solve(int n) {
    vector<int> ANS;
    int x = query(1, 2);
    for (int i = 3; i <= n; i++) {
        p1[i] = query(i-1, i);
        p2[i] = query(i-2, i);
    }
    a[1] = x;
    a[2] = 0;
    for (int i = 3; i <= n; i++) {
        int val =a[i-1] + p1[i];
        a[i] = val;
        if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
        else a[i] = a[i-1] - p1[i];

    }
    int mn = n;
    for (int i = 1; i <= n; i++) {
        mn = min(mn, a[i]);
    }
    if(mn > 0) mn = -(mn-1);
    else mn = abs(mn-1);
    bool ac = true;
    int pos1, posn;
    for (int i = 1; i <= n; i++) {
        a[i]+=mn;
        mark[a[i]] = true;
        if(a[i] > n) ac = false;
        if(a[i] == 1) pos1 = i;
        if(a[i] == n) posn = i;
    }
    for (int i = 1; i <= n; i++) if(!mark[i]) ac = false;
    if(pos1 > posn) ac = false;
    if(ac) {
        //ANSWER
        for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
        ANSWER(ANS);
    }
    else {
        a[1] = 0, a[2] = x;
        for (int i = 3; i <= n; i++) {
            int val = a[i-1] + p1[i];
            a[i] = val;
            if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
            else a[i] = a[i-1] - p1[i];
        }
        int mn = n;
        for (int i = 1; i <= n; i++) {
            mn = min(mn, a[i]);
        }
        if(mn > 0) mn = -(mn-1);
        else mn = abs(mn-1);
        for (int i = 1; i <= n; i++) a[i] += mn;
        for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
        ANSWER(ANS);
    }
}

Compilation message

xylophone.cpp: In function 'void ANSWER(std::vector<int>&)':
xylophone.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < v.size(); i++) answer(i+1,v[i]);
      |                     ~~^~~~~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:46:5: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     if(ac) {
      |     ^~
xylophone.cpp:46:5: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 444 KB Output is correct
19 Correct 13 ms 448 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 11 ms 704 KB Output is correct
23 Correct 10 ms 444 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 6 ms 448 KB Output is correct
27 Correct 9 ms 592 KB Output is correct
28 Correct 9 ms 344 KB Output is correct
29 Correct 10 ms 448 KB Output is correct
30 Correct 12 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 444 KB Output is correct
19 Correct 13 ms 448 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 11 ms 704 KB Output is correct
23 Correct 10 ms 444 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 6 ms 448 KB Output is correct
27 Correct 9 ms 592 KB Output is correct
28 Correct 9 ms 344 KB Output is correct
29 Correct 10 ms 448 KB Output is correct
30 Correct 12 ms 704 KB Output is correct
31 Correct 23 ms 856 KB Output is correct
32 Correct 28 ms 456 KB Output is correct
33 Correct 38 ms 452 KB Output is correct
34 Correct 64 ms 344 KB Output is correct
35 Correct 69 ms 676 KB Output is correct
36 Correct 61 ms 952 KB Output is correct
37 Correct 57 ms 456 KB Output is correct
38 Correct 61 ms 696 KB Output is correct
39 Correct 52 ms 956 KB Output is correct
40 Correct 55 ms 692 KB Output is correct
41 Correct 48 ms 696 KB Output is correct
42 Correct 53 ms 608 KB Output is correct
43 Correct 53 ms 860 KB Output is correct
44 Correct 48 ms 344 KB Output is correct
45 Correct 55 ms 600 KB Output is correct
46 Correct 58 ms 704 KB Output is correct
47 Correct 44 ms 856 KB Output is correct
48 Correct 52 ms 592 KB Output is correct
49 Correct 63 ms 456 KB Output is correct
50 Correct 56 ms 344 KB Output is correct
51 Correct 62 ms 848 KB Output is correct
52 Correct 47 ms 696 KB Output is correct
53 Correct 71 ms 460 KB Output is correct
54 Correct 44 ms 592 KB Output is correct
55 Correct 50 ms 600 KB Output is correct
56 Correct 47 ms 692 KB Output is correct
57 Correct 53 ms 452 KB Output is correct
58 Correct 65 ms 700 KB Output is correct
59 Correct 75 ms 592 KB Output is correct
60 Correct 57 ms 704 KB Output is correct