QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#588117#8239. Mysterious Treeq_zhsWA 0ms3532kbC++171.6kb2024-09-25 01:39:502024-09-25 01:39:50

Judging History

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

  • [2024-09-25 01:39:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3532kb
  • [2024-09-25 01:39:50]
  • 提交

answer

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

// Function to compute ceil(n / 2)
int ceil_div2(int n) {
    return (n + 1) / 2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        // Compute the number of queries allowed
        int max_queries = ceil_div2(n) + 3;
        // Initialize count of connections for vertex 1
        int count = 0;
        // To keep track of queries done
        int queries_done = 0;
        // To store vertices already queried to avoid duplicates
        // Not strictly necessary since we're querying vertex 1 with distinct vertices
        for(int i=2; i<=n && queries_done < max_queries; ++i){
            // Query "? 1 i"
            cout << "? " << 1 << " " << i << "\n";
            cout.flush();
            // Read the response
            string response;
            cin >> response;
            if(response == "1"){
                count++;
                // If count exceeds 2, it's a star
                if(count > 2){
                    break;
                }
            }
            queries_done++;
        }
        // Decide based on the count
        if(count > 2){
            // It's a star
            cout << "! 2\n";
            cout.flush();
        }
        else{
            // It's a chain
            cout << "! 1\n";
            cout.flush();
        }
        // It's important to read any remaining responses to keep the interactor in sync
        // However, since the interactor is adaptive, no further actions are needed
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

2
4
1
0
0
4
0
1
0

output:

? 1 2
? 1 3
? 1 4
! 1
? 1 2
? 1 3
? 1 4
! 1

result:

wrong answer Wrong prediction (test case 2)