Submission #774028

# Submission time Handle Problem Language Result Execution time Memory
774028 2023-07-05T11:11:48 Z Dan4Life Xylophone (JOI18_xylophone) C++17
0 / 100
0 ms 208 KB
#include "xylophone.h"
#include <iostream>
using namespace std;

int a[5010], ok[5010];

void Answer(int x, int v){
    answer(x,v); a[x]=v; ok[x]=1; 
}

void solve(int n) {
    int l = 1, r = n-1;
    while(l<r){
        int mid = (l+r)/2;
        if(query(mid,n)==n-1) r=mid;
        else l=mid+1;
    }
    Answer(l,1);
    if(l!=1) Answer(l-1,query(l-1,l)+1);
    Answer(l+1,query(l,l+1)+1);
    for(int i = l-2; i>=1; i--){
        int dif = query(i,i+1);
        int x1 = a[i+1]-dif;
        int x2 = a[i+1]+dif;
        if(ok[x1]) swap(x1,x2);
        if(ok[x2]) ok[x1]=1,answer(i,x1);
        else{
            int dif2 = query(i,i+2);
			if(abs(x1-a[i+2])==dif2) answer(i,x1);
			else answer(i,x2);
        }
    }
	for(int i = l+2; i<=n; i++){
        int dif = query(i-1,i);
        int x1 = a[i-1]-dif;
        int x2 = a[i-1]+dif;
        if(ok[x1]) swap(x1,x2);
        if(ok[x2]) ok[x1]=1,answer(i,x1);
        else{
            int dif2 = query(i-2,i);
			if(abs(x1-a[i+2])==dif2) answer(i,x1);
			else answer(i,x2);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 0 ms 208 KB Wrong Answer [4]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 0 ms 208 KB Wrong Answer [4]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 0 ms 208 KB Wrong Answer [4]
3 Halted 0 ms 0 KB -