Submission #1297732

#TimeUsernameProblemLanguageResultExecution timeMemory
1297732danglayloi1Xylophone (JOI18_xylophone)C++20
100 / 100
28 ms464 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
const int nx=5005;
// int query(int s, int t)
// {
//     cout<<s<<' '<<t<<'\n';
//     int v;
//     cin>>v;
//     return v;
// }
// void answer(int i, int a)
// {
//     cout<<a<<' ';
// }
void solve(int n)
{
    vector<int> d1(n+1), d2(n+1), d(n+1, 0);
    vector<bool> ok(n+1);
    for(int i = 1; i < n; i++)
        d1[i]=query(i, i+1);
    for(int i = 1; i < n-1; i++)
        d2[i]=query(i, i+2);
    for(int i = 2; i < n; i++)
        ok[i]=(d1[i-1]+d1[i]==d2[i-1]);
    int sus=-1;
    d[1]=0;
    d[2]=sus*d1[1];
    for(int i = 3; i <= n; i++)
    {
        if(!ok[i-1]) sus*=-1;
        d[i]=d[i-1]+sus*d1[i-1];
    }
    int mi=0;
    for(int i = 1; i <= n; i++)
        mi=min(mi, d[i]);
    int p1, pn;
    for(int i = 1; i <= n; i++)
    {
        d[i]=d[i]-mi+1;
        if(d[i]==1) p1=i;
        if(d[i]==n) pn=i;
    }
    if(p1<pn)
    {
        for(int i = 1; i <= n; i++)
            answer(i, d[i]);
        return;
    }
    sus=1;
    d[1]=0;
    d[2]=sus*d1[1];
    for(int i = 3; i <= n; i++)
    {
        if(!ok[i-1]) sus*=-1;
        d[i]=d[i-1]+sus*d1[i-1];
    }
    mi=0;
    for(int i = 1; i <= n; i++)
        mi=min(mi, d[i]);
    p1, pn;
    for(int i = 1; i <= n; i++)
    {
        d[i]=d[i]-mi+1;
        if(d[i]==1) p1=i;
        if(d[i]==n) pn=i;
    }
    if(p1<pn)
    {
        for(int i = 1; i <= n; i++)
            answer(i, d[i]);
        return;
    }
    assert(0);
}
// int main()
// {
//     // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     solve(5);
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...