제출 #330808

#제출 시각아이디문제언어결과실행 시간메모리
330808FidiskXylophone (JOI18_xylophone)C++14
0 / 100
1 ms364 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;

const ll mod=1e9+7;

bool ok[5009];
int a[5009],type[5009],ans[5009],last,i,j,n,b[5009];

bool check(int x,int t) {
    last=1;
    ms(ok,false);
    ans[1]=x;
    ok[x]=true;
    if (t==1) {
        for (int ii=1;ii<=n;ii++) {
            if (type[ii]==1) {
                if (last==1) {
                    ans[ii]=ans[ii-1]+a[ii-1];
                }
                else {
                    ans[ii]=ans[ii-1]-a[ii-1];
                }
            }
            else {
                if (last==1) {
                    ans[ii]=ans[ii-1]-a[ii-1];
                }
                else {
                    ans[ii]=ans[ii-1]+a[ii-1];
                }
            }
            if (!ok[ans[ii]]) {
                ok[ans[ii]]=true;
            }
            else {
                return false;
            }
        }
    }
    else {
        last=0;
        for (int ii=1;ii<=n;ii++) {
            if (type[ii]==1) {
                if (last==1) {
                    ans[ii]=ans[ii-1]+a[ii-1];
                }
                else {
                    ans[ii]=ans[ii-1]-a[ii-1];
                }
            }
            else {
                if (last==1) {
                    ans[ii]=ans[ii-1]-a[ii-1];
                }
                else {
                    ans[ii]=ans[ii-1]+a[ii-1];
                }
            }
            if (!ok[ans[ii]]&&ans[ii]>=1&&ans[ii]<=n) {
                ok[ans[ii]]=true;
            }
            else {
                return false;
            }
        }
    }
    return true;
}

void solve(int n) {
    if (n==2) {
        answer(1,1);
        answer(2,2);
        return;
    }
    for (i=1;i<n;i++) {
        a[i]=query(i,i+1);
    }
    for (i=1;i<n-1;i++) {
        b[i]=query(i,i+2);
    }
    for (i=1;i<=n-2;i++) {
        if (a[i]==b[i]||a[i+1]==b[i]) {
            type[i+1]=1;
        }
        else {
            type[i+1]=0;
        }
    }
    for (i=1;i<=n;i++) {
        if (check(i,1)) {
            for (j=1;j<=n;j++) {
                answer(i,a[i]);
            }
        }
        if (check(i,0)) {
            for (j=1;j<=n;j++) {
                answer(i,a[i]);
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...