Submission #1032525

# Submission time Handle Problem Language Result Execution time Memory
1032525 2024-07-23T23:43:17 Z vjudge1 Xylophone (JOI18_xylophone) C++17
47 / 100
62 ms 20764 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
static int A[5000];
int sv[5010][5010];
int myqry(int l,int r){
    if(l>r)swap(l,r);
    if(l==r)return 0;
    if(sv[l][r])return sv[l][r];
    return sv[l][r]=query(l,r);
}
int ans[5010];
int makesense(int a,int b,int c,int ac){
    return ac==max({a,b,c})-min({a,b,c});
}

void solve(int N) {
    int l=1,r=N-1,res=0;
    while(l<=r){
        int mid=l+r>>1;
        if(myqry(mid,N)==N-1)
            res=mid,l=mid+1;
        else r=mid-1;
    }
    int posof1=res;
    ans[posof1]=1;
    if(posof1>1)
        ans[posof1-1]=myqry(posof1-1,posof1)+1;
    ans[posof1+1]=myqry(posof1,posof1+1)+1;
    for(int i=posof1-2;i>0;i--){
        int k=myqry(i,i+1);
        if(ans[i+1]-k<1)
            ans[i]=ans[i+1]+k;
        else if(ans[i+1]+k>N)
            ans[i]=ans[i+1]-k;
        else {
            int c=query(i,i+2);
            if(makesense(ans[i+1]-k,ans[i+1],ans[i+2],c))
                ans[i]=ans[i+1]-k;
            else ans[i]=ans[i+1]+k;
        }
    }
    for(int i=posof1+2;i<=N;i++){
        int k=myqry(i-1,i);
        if(ans[i-1]-k<1)
            ans[i]=ans[i-1]+k;
        else if(ans[i+1]+k>N)
            ans[i]=ans[i-1]-k;
        else {
            int c=query(i-2,i);
            if(makesense(ans[i-1]-k,ans[i-1],ans[i-2],c))
                ans[i]=ans[i-1]-k;
            else ans[i]=ans[i-1]+k;
        }
    }
    for(int i=1;i<=N;i++)
        answer(i,ans[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:20:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |         int mid=l+r>>1;
      |                 ~^~
xylophone.cpp: At global scope:
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
    4 | static int A[5000];
      |            ^
# 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 476 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 784 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 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 476 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 784 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 2 ms 1112 KB Output is correct
17 Correct 6 ms 2136 KB Output is correct
18 Correct 8 ms 3704 KB Output is correct
19 Correct 13 ms 4440 KB Output is correct
20 Correct 11 ms 4440 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 10 ms 4500 KB Output is correct
23 Correct 10 ms 4440 KB Output is correct
24 Correct 8 ms 4440 KB Output is correct
25 Correct 9 ms 4296 KB Output is correct
26 Correct 11 ms 4484 KB Output is correct
27 Correct 11 ms 4696 KB Output is correct
28 Correct 9 ms 4268 KB Output is correct
29 Correct 10 ms 4440 KB Output is correct
30 Correct 9 ms 4440 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 476 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 784 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 2 ms 1112 KB Output is correct
17 Correct 6 ms 2136 KB Output is correct
18 Correct 8 ms 3704 KB Output is correct
19 Correct 13 ms 4440 KB Output is correct
20 Correct 11 ms 4440 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 10 ms 4500 KB Output is correct
23 Correct 10 ms 4440 KB Output is correct
24 Correct 8 ms 4440 KB Output is correct
25 Correct 9 ms 4296 KB Output is correct
26 Correct 11 ms 4484 KB Output is correct
27 Correct 11 ms 4696 KB Output is correct
28 Correct 9 ms 4268 KB Output is correct
29 Correct 10 ms 4440 KB Output is correct
30 Correct 9 ms 4440 KB Output is correct
31 Correct 22 ms 9204 KB Output is correct
32 Correct 40 ms 12840 KB Output is correct
33 Correct 42 ms 18000 KB Output is correct
34 Correct 50 ms 20576 KB Output is correct
35 Correct 56 ms 20620 KB Output is correct
36 Incorrect 62 ms 20764 KB Wrong Answer [2]
37 Halted 0 ms 0 KB -