QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#521447#2199. Intriguing SelectionsocpiteWA 27ms3704kbC++234.0kb2024-08-16 10:55:102024-08-16 10:55:10

Judging History

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

  • [2024-08-16 10:55:10]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3704kb
  • [2024-08-16 10:55:10]
  • 提交

answer

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

const int maxn = 205;

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

vector<int> g[maxn], rg[maxn];

bool vis[maxn];
bool asked[maxn][maxn];

void dfs(int x, int &cnt){
    vis[x] = 1;
    cnt++;
    for(auto v: g[x])if(!vis[v])dfs(v, cnt);
}

void rdfs(int x, int &cnt){
    vis[x] = 1;
    cnt++;
    for(auto v: rg[x])if(!vis[v])rdfs(v, cnt);
}

bool query(int a, int b){
    cout << "? " << a << " " << b << endl;
    char c;
    cin >> c;
    return c == '<';
}

void solve_3(){
    int arr[4] = {1, 2, 3, 0};
    // arr[0] < arr[1], arr[2] < arr[3]
    for(int i = 4; i <= 6; i++){
        for(int j = 0; j < 4; j++)if(!arr[j])arr[j] = i;
        if(!query(arr[0], arr[1]))swap(arr[0], arr[1]);
        if(!query(arr[2], arr[3]))swap(arr[2], arr[3]);
        if(query(arr[0], arr[2]))arr[0] = 0;
        else arr[2] = 0; 
    }
    cout << "!" << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        if(n == 3){
            solve_3();
            continue;
        }
        memset(asked, 0, sizeof(asked));
        vector<pair<int, int>> vec;
        for(int i = 1; i <= 2*n; i++){
            g[i].clear();
            rg[i].clear();
            for(int j = 1; j < i; j++)vec.push_back({i, j});
        }
        shuffle(vec.begin(), vec.end(), rng);
        while(true){
            bool br = 1;
            for(auto p: vec){
                if(asked[p.first][p.second])continue;
                bool f1 = 0, f2 = 0;
                int cnt = 0;
                memset(vis, 0, sizeof(vis));
                dfs(p.first, cnt);
                if(cnt > n)f1 = 1;

                memset(vis, 0, sizeof(vis));
                rdfs(p.first, cnt);
                if(cnt > n)f1 = 1;
                cnt = 0;
                memset(vis, 0, sizeof(vis));
                dfs(p.second, cnt);
                if(cnt > n)f2 = 1;

                cnt = 0;
                memset(vis, 0, sizeof(vis));
                rdfs(p.second, cnt);
                if(cnt > n)f2 = 1;


                if(f1 || f2)continue;
                asked[p.first][p.second] = 1;
                cout << "? " << p.first << " " << p.second << endl;

                char c;
                cin >> c;
                if(c == '>'){
                    g[p.first].push_back(p.second);
                    rg[p.second].push_back(p.first);
                }
                else {
                    rg[p.first].push_back(p.second);
                    g[p.second].push_back(p.first);
                }
                br = 0;
            }
            if(br)break;
        }
        while(true){
            bool br = 1;
            for(auto p: vec){
                if(asked[p.first][p.second])continue;
                bool f1 = 0, f2 = 0;
                int cnt = 0;
                memset(vis, 0, sizeof(vis));
                dfs(p.first, cnt);
                if(cnt > n)f1 = 1;

                memset(vis, 0, sizeof(vis));
                rdfs(p.first, cnt);
                if(cnt > n)f1 = 1;
                cnt = 0;
                memset(vis, 0, sizeof(vis));
                dfs(p.second, cnt);
                if(cnt > n)f2 = 1;

                cnt = 0;
                memset(vis, 0, sizeof(vis));
                rdfs(p.second, cnt);
                if(cnt > n)f2 = 1;


                if(f1 && f2)continue;
                asked[p.first][p.second] = 1;
                cout << "? " << p.first << " " << p.second << endl;

                char c;
                cin >> c;
                if(c == '>'){
                    g[p.first].push_back(p.second);
                    rg[p.second].push_back(p.first);
                }
                else {
                    rg[p.first].push_back(p.second);
                    g[p.second].push_back(p.first);
                }
                br = 0;
            }
            if(br)break;
        }
        cout << "!" << endl;
    }
}

詳細信息

Test #1:

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

input:

2
3
>
>
>
<
<
>
<
<
>
3
<
<
<
<
<
<
>
<
>

output:

? 1 2
? 3 4
? 2 4
? 2 1
? 5 3
? 2 5
? 2 1
? 6 3
? 2 6
!
? 1 2
? 3 4
? 1 3
? 5 2
? 3 4
? 5 3
? 6 2
? 3 4
? 2 3
!

result:

ok 2 cases

Test #2:

score: 0
Accepted
time: 6ms
memory: 3704kb

input:

1111
3
<
>
<
<
<
<
<
<
>
3
>
>
<
>
<
<
<
<
<
3
>
>
>
<
<
>
<
<
>
3
>
>
>
<
<
>
<
<
>
3
<
>
>
<
<
>
<
>
>
3
>
<
<
<
<
>
<
>
<
3
<
>
<
>
<
>
<
<
>
3
<
>
>
<
<
<
<
<
<
3
<
>
>
<
>
>
<
<
>
3
>
>
<
>
<
<
<
<
>
3
>
>
<
>
<
>
<
<
>
3
>
>
>
<
<
>
<
<
>
3
<
<
<
>
<
<
<
<
>
3
<
>
>
<
<
>
<
<
<
3
<
<
>
<
<
<
<...

output:

? 1 2
? 3 4
? 1 4
? 5 2
? 4 3
? 5 4
? 6 2
? 4 3
? 6 4
!
? 1 2
? 3 4
? 2 4
? 5 1
? 4 3
? 1 4
? 6 5
? 4 3
? 6 4
!
? 1 2
? 3 4
? 2 4
? 2 1
? 5 3
? 2 5
? 2 1
? 6 3
? 2 6
!
? 1 2
? 3 4
? 2 4
? 2 1
? 5 3
? 2 5
? 2 1
? 6 3
? 2 6
!
? 1 2
? 3 4
? 1 4
? 1 2
? 5 3
? 1 5
? 1 2
? 6 3
? 1 3
!
? 1 2
? 3 4
? 2 3
? ...

result:

ok 1111 cases

Test #3:

score: -100
Wrong Answer
time: 27ms
memory: 3660kb

input:

625
4
>
<
>
<
<
<
>
<
>
>
<
<
>
>
>
4
>
<
<
>
>
<
<
>
>
<
>
>
>
<
>
4
>
<
>
<
>
>
>
<
>
>
>
<
>
>
<
4
<
<
>
>
<
>
<
>
<
<
<
>
>
4
>
>
<
>
>
<
<
4
<
>
>
>
<
>
<
<
>
>
<
<
>
4
<
>
<
>
<
<
>
>
<
>
>
>
<
<
<
4
<
<
>
>
>
<
>
<
>
>
>
<
4
<
>
>
<
>
>
<
<
<
>
<
<
<
>
<
<
4
>
>
>
>
>
>
<
>
<
<
<
4
>
<
>
>
>
...

output:

? 7 6
? 8 7
? 5 4
? 8 3
? 8 5
? 4 2
? 6 1
? 6 2
? 5 1
? 4 3
? 8 4
? 8 6
? 5 3
? 6 3
? 6 4
!
? 3 2
? 8 3
? 5 3
? 8 5
? 6 5
? 6 3
? 6 2
? 4 2
? 8 4
? 7 4
? 6 1
? 8 7
? 8 2
? 5 2
? 7 2
!
? 8 3
? 5 3
? 6 3
? 7 2
? 8 1
? 4 1
? 7 5
? 6 2
? 7 1
? 4 3
? 8 7
? 5 4
? 6 4
? 8 4
? 7 4
!
? 6 4
? 5 2
? 7 4
? 7 2
...

result:

wrong answer Case 1: all players in topn are comparable