Submission #197502

# Submission time Handle Problem Language Result Execution time Memory
197502 2020-01-21T13:16:37 Z handlename Xylophone (JOI18_xylophone) C++17
100 / 100
116 ms 512 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int n,arr[5001][2];
int queries[5001][2];
void solve(int N){
    n=N;
    for (int j=0;j<2;j++){
        int temp;
        if (queries[2][0]!=0){
            temp=queries[2][0];
        }
        else {
            temp=query(1,2);
            queries[2][0]=temp;
        }
        if (j==0) arr[2][j]=arr[1][j]+temp;
        else arr[2][j]=arr[1][j]-temp;
        for (int i=3;i<=n;i++){
            int one;
            int two;
            if (queries[i][0]!=0){
                one=queries[i][0];
                two=queries[i][1];
            }
            else {
                one=query(i-1,i);
                two=query(i-2,i);
                queries[i][0]=one;
                queries[i][1]=two;
            }
            int diff=abs(arr[i-1][j]-arr[i-2][j]);
            if (arr[i-1][j]>arr[i-2][j]){
                if (one+diff==two){
                    arr[i][j]=arr[i-1][j]+one;
                }
                else arr[i][j]=arr[i-1][j]-one;
            }
            else {
                if (one+diff==two){
                    arr[i][j]=arr[i-1][j]-one;
                }
                else arr[i][j]=arr[i-1][j]+one;
            }
        }
        bool works=true;
        int mini=1e9,lpos,rpos;
        for (int i=1;i<=n;i++) mini=min(mini,arr[i][j]);
        for (int i=1;i<=n;i++){
            arr[i][j]+=(1-mini);
            if (arr[i][j]<1 || arr[i][j]>n) works=false;
            if (arr[i][j]==1) lpos=i;
            if (arr[i][j]==n) rpos=i;
        }
        if (lpos>rpos) works=false;
        if (works){
            for (int i=1;i<=n;i++) answer(i,arr[i][j]);
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:55:9: warning: 'rpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (lpos>rpos) works=false;
         ^~
xylophone.cpp:55:9: warning: 'lpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 252 KB Output is correct
4 Correct 4 ms 316 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 252 KB Output is correct
4 Correct 4 ms 316 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 400 KB Output is correct
16 Correct 7 ms 328 KB Output is correct
17 Correct 12 ms 248 KB Output is correct
18 Correct 19 ms 328 KB Output is correct
19 Correct 26 ms 332 KB Output is correct
20 Correct 23 ms 504 KB Output is correct
21 Correct 21 ms 504 KB Output is correct
22 Correct 24 ms 452 KB Output is correct
23 Correct 23 ms 376 KB Output is correct
24 Correct 21 ms 324 KB Output is correct
25 Correct 21 ms 380 KB Output is correct
26 Correct 25 ms 248 KB Output is correct
27 Correct 36 ms 376 KB Output is correct
28 Correct 22 ms 376 KB Output is correct
29 Correct 13 ms 316 KB Output is correct
30 Correct 24 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 252 KB Output is correct
4 Correct 4 ms 316 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 400 KB Output is correct
16 Correct 7 ms 328 KB Output is correct
17 Correct 12 ms 248 KB Output is correct
18 Correct 19 ms 328 KB Output is correct
19 Correct 26 ms 332 KB Output is correct
20 Correct 23 ms 504 KB Output is correct
21 Correct 21 ms 504 KB Output is correct
22 Correct 24 ms 452 KB Output is correct
23 Correct 23 ms 376 KB Output is correct
24 Correct 21 ms 324 KB Output is correct
25 Correct 21 ms 380 KB Output is correct
26 Correct 25 ms 248 KB Output is correct
27 Correct 36 ms 376 KB Output is correct
28 Correct 22 ms 376 KB Output is correct
29 Correct 13 ms 316 KB Output is correct
30 Correct 24 ms 376 KB Output is correct
31 Correct 56 ms 376 KB Output is correct
32 Correct 65 ms 360 KB Output is correct
33 Correct 87 ms 392 KB Output is correct
34 Correct 103 ms 504 KB Output is correct
35 Correct 106 ms 376 KB Output is correct
36 Correct 103 ms 428 KB Output is correct
37 Correct 112 ms 476 KB Output is correct
38 Correct 54 ms 396 KB Output is correct
39 Correct 104 ms 452 KB Output is correct
40 Correct 98 ms 380 KB Output is correct
41 Correct 101 ms 376 KB Output is correct
42 Correct 103 ms 424 KB Output is correct
43 Correct 114 ms 432 KB Output is correct
44 Correct 108 ms 504 KB Output is correct
45 Correct 107 ms 400 KB Output is correct
46 Correct 102 ms 380 KB Output is correct
47 Correct 99 ms 376 KB Output is correct
48 Correct 77 ms 376 KB Output is correct
49 Correct 97 ms 448 KB Output is correct
50 Correct 106 ms 376 KB Output is correct
51 Correct 105 ms 488 KB Output is correct
52 Correct 100 ms 376 KB Output is correct
53 Correct 104 ms 376 KB Output is correct
54 Correct 102 ms 352 KB Output is correct
55 Correct 101 ms 376 KB Output is correct
56 Correct 94 ms 444 KB Output is correct
57 Correct 102 ms 512 KB Output is correct
58 Correct 116 ms 376 KB Output is correct
59 Correct 114 ms 376 KB Output is correct
60 Correct 70 ms 316 KB Output is correct