QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527702#4204. Guessing Circlebachbeo2007WA 1ms3732kbC++232.3kb2024-08-22 18:22:102024-08-22 18:22:10

Judging History

This is the latest submission verdict.

  • [2024-08-22 18:22:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3732kb
  • [2024-08-22 18:22:10]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn = 15005;
const int inf = 1e9;

int n,x[2*maxn],rt[2*maxn];
vector<int> pos[maxn],val;
pair<int,int> A[maxn],B[maxn];

pair<int,int> merge(pair<int,int> p,pair<int,int> q){
    auto [a,b]=p;
    auto [c,d]=q;
    if(a==-1 || c==-1) return {-1,-1};
    
    if(a>c) swap(a,c),swap(b,d);
    if(b>=a){
        if(d>=c){
            int r=min(b,d);
            if(r>=c) return {c,r};
            else return {-1,-1};
        }
        else{
            if(b>=c) return {c,b};
            else return {-1,-1};
        }
    }
    else{
        if(d>=c) return {c,d};
        else return {c,min(b,d)};
    }
    return {-1,-1};
}

bool get(pair<int,int> p){
    if(p.first==-1) return false;
    if(p.second<p.first) p.second+=n;
    return rt[p.first]<=p.second;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x[i];x[n+i]=x[i];
        if(pos[x[i]].empty()) val.push_back(x[i]);
        pos[x[i]].push_back(i);
    }
    sort(val.begin(),val.end());
    for(int i=0;i<2*n;i++) rt[i]=inf;
    for(int i:val){
        for(int j=0;j<(int)pos[i].size();j++){
            int l=pos[i][j],r=(j?pos[i][j-1]:pos[i].back());
            if(l>r) rt[l]=min(rt[l],r+n);
            else{
                rt[l]=min(rt[l],r);
                rt[l+n]=min(rt[l+n],r+n);
            }
        }
    }
    for(int i=2*n-2;i>=0;i--) rt[i]=min(rt[i],rt[i+1]);
    if(n==2){
        cout << "none\n";
        return 0;
    }
    int sz=(n-1)/2;
    for(int i:val){
        A[i]=B[i]={0,n-1};
        for(int j:pos[i]){
            int l=(j+1)%n,r=(j+sz)%n;
            A[i]=merge(A[i],{l,r});
            l=(j-sz+n)%n,r=(j-1+n)%n;
            B[i]=merge(B[i],{l,r});
        }
    }
    bool none=true;
    for(int i:val){
        bool check=true;
        for(int j:val){
            if(i==j) continue;
            auto S=merge(A[i],B[j]);
            auto T=merge(A[j],B[i]);
            if(!get(S) && !get(T)){
                check=false;
                break;
            }
        }
        if(check){
            cout << i << '\n';
            none=false;
        }
    }
    if(none) cout << "none\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

input:

3
1 2 3

output:

1
2
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

3
1 1 2

output:

none

result:

ok single line: 'none'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4
1 2 1 3

output:

none

result:

ok single line: 'none'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

5
1 2 3 4 1

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3636kb

input:

7
5 2 1 7 3 6 5

output:

2
5

result:

wrong answer 3rd lines differ - expected: '6', found: ''