QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#195712#5156. Going in Circleskevinshan#RE 0ms0kbC++202.4kb2023-10-01 06:27:572023-10-01 06:27:58

Judging History

你现在查看的是最新测评结果

  • [2023-10-01 06:27:58]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-01 06:27:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

char query(int type) {
    if (type==0) {
        cout << "? right" << '\n';
        cout.flush();
    } else if(type ==1) {
        cout << "? left" << '\n';
        cout.flush();
    } else {
        cout << "? flip" << '\n';
        cout.flush();
    }
    char x;cin>>x;
    return x;
}

#define ts to_string

string pattern;
string pattern2;

char mine() {
    query(2);
    return query(2);
}

bool test(int n) {
    pattern="";
    for (int i=0;i<n;i++) {
        if (rng()%2) {
            char c = query(2);
            pattern.pop_back();
            pattern+=c;
        }
        pattern += i?query(0):mine();
    }
    for (int j=0;j<3;j++) {
        for (int i=0;i<n;i++) {
            char c = query(0);
            if (pattern[i]!=c) {
                for (int k=0;k<i;k++) {
                    query(1);
                }
                return false;
            }

            if (rng()%2) {
                c = query(2);
            }
            pattern2+=c;
        }
        pattern = pattern2;
        pattern2 = "";
    }
    return true;
}

void ans(int n) {
    cout << "! " << n << endl;
    exit(0);
}

const int BL = 40;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    char x;cin>>x;
    
    pattern+=x;
    for (int i=3;i<7;i++) {
        pattern = "";
        if(test(i)){
            ans(i);
        }
    }

    for(int i=0;i<6;i++) {
        query(0);
    }

    // 180 queries below?
    int ind = 1;
    for (int i=0;i<40;i++) {
        char x = query(0);
        if (pattern[ind] == x) {
            ind++;
            if (ind==7) {
                ans(i+1);
            }
        } else {
            ind = 0;
        }
    }

    for (int i=0;i<46;i++) {
        query(1);
    }

    pattern = "";
    for (int i=0;i<BL;i++) {
        if(rng()%2) {
            query(3);
        }
        query(0);
    }

    ind=0;
    for (int i=0;i<5e4;i++) {
        char c = query(0);
        if (pattern[ind] == c) {
            ind++;
            if (ind == BL) {
                ans(i);

                // or go again and reconfirm
            }
        } else {
            ind=0;
        }
    }
    ans(-1);
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

0
1

output:

? flip

result: