Submission #1016912

# Submission time Handle Problem Language Result Execution time Memory
1016912 2024-07-08T15:24:34 Z lazar3141 Xylophone (JOI18_xylophone) C++17
47 / 100
61 ms 344 KB
#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include "xylophone.h"

using namespace std;

static const int N_MAX = 5000;
static const int Q_MAX = 10000;
static int N;
static int A[N_MAX];
static bool used[N_MAX];
static int query_c;
static int answer_c;

void solve(int N) {
    vector<int> v(N+1, 0);
	int l = 2, r = N;
	int rez = -1;
	while(l<=r){
        int mid = (l+r)/2;
        if(query(1, mid)!=N-1){
            l = mid+1;
        } else{
            rez = mid;
            r = mid-1;

        }
	}
    answer(rez, N);
    v[rez] = N;
    if(rez!=1){
        int x = N-query(rez-1, rez);
        answer(rez-1, x);
        v[rez-1] = x;
    }
    if(rez!=N){
        int x = N-query(rez, rez+1);
        answer(rez+1, x);
        v[rez+1] = x;
    }
    for(int i = rez-2;i>=1;i--){
        int d1 = query(i, i+1), d2 = query(i, i+2);
        int ans = 0;
        if(v[i+1]>v[i+2]){
            if(d1+v[i+1]-v[i+2]==d2) ans = v[i+1]+d1;
            else ans = v[i+1]-d1;
        } else{
            if(d1+v[i+2]-v[i+1]==d2) ans = v[i+1]-d1;
            else ans = v[i+1]+d1;
        }
        answer(i, ans);
        v[i] = ans;
    }
    for(int i = rez+2;i<=N;i++){
        int d1 = query(i-1, i), d2 = query(i-2, i);
        int ans = 0;
        if(v[i-1]>v[i-2]){
            if(d1+v[i-1]-v[i-2]==d2) ans = v[i-1]+d1;
            else ans = v[i-1]-d1;
        } else{
            if(d1+v[i-2]-v[i-1]==d2) ans = v[i-1]-d1;
            else ans = v[i-1]+d1;
        }
        answer(i, ans);
        v[i] = ans;
    }
}

Compilation message

xylophone.cpp:14:12: warning: 'answer_c' defined but not used [-Wunused-variable]
   14 | static int answer_c;
      |            ^~~~~~~~
xylophone.cpp:13:12: warning: 'query_c' defined but not used [-Wunused-variable]
   13 | static int query_c;
      |            ^~~~~~~
xylophone.cpp:12:13: warning: 'used' defined but not used [-Wunused-variable]
   12 | static bool used[N_MAX];
      |             ^~~~
xylophone.cpp:11:12: warning: 'A' defined but not used [-Wunused-variable]
   11 | static int A[N_MAX];
      |            ^
xylophone.cpp:10:12: warning: 'N' defined but not used [-Wunused-variable]
   10 | static int N;
      |            ^
# Verdict Execution time Memory 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 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 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory 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 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 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 8 ms 340 KB Output is correct
20 Correct 12 ms 340 KB Output is correct
21 Correct 9 ms 340 KB Output is correct
22 Correct 13 ms 344 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Correct 16 ms 344 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 13 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 12 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 9 ms 344 KB Output is correct
# Verdict Execution time Memory 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 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 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 8 ms 340 KB Output is correct
20 Correct 12 ms 340 KB Output is correct
21 Correct 9 ms 340 KB Output is correct
22 Correct 13 ms 344 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Correct 16 ms 344 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 13 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 12 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 9 ms 344 KB Output is correct
31 Correct 25 ms 344 KB Output is correct
32 Correct 32 ms 344 KB Output is correct
33 Correct 40 ms 344 KB Output is correct
34 Incorrect 61 ms 344 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -