Submission #1067581

# Submission time Handle Problem Language Result Execution time Memory
1067581 2024-08-20T20:44:05 Z Unforgettablepl Park (JOI17_park) C++17
10 / 100
45 ms 604 KB
#include "park.h"
#include <bits/stdc++.h>
using namespace std;

static int Place[1400];

void strat1(int N) {
    for(int i=0;i<N;i++) {
        for(int j=i+1;j<N;j++) {
            Place[i]=Place[j]=1;
            if(Ask(i,j,Place))Answer(i,j);
            Place[i]=Place[j]=0;
        }
    }
}

void stratTree(int N) {
    vector<bool> used(N);
    vector<vector<int>> adj(N);
    used[0]=true;
    for(int y=1;y<N;y++) {
        if(used[y])continue;
        stack<int> s;
        s.emplace(y);
        vector<int> arm;
        while(!s.empty()) {
            int curr = s.top();s.pop();
            used[curr]=true;
            function check = [&](int x) {
                for(int i=0;i<x;i++)Place[i]=true;
                for(int i=0;i<N;i++)if(used[i])Place[i]=true;
                assert(curr>0);
                bool ans = Ask(0,curr,Place);
                for(int i=0;i<N;i++)Place[i]=false;
                return !ans;
            };
            int ans = -1;
            for(int jump=1024;jump;jump/=2) {
                if(ans+jump>=N)continue;
                if(check(ans+jump))ans+=jump;
            }
            if(ans==-1)arm.emplace_back(curr);
            else {
                s.emplace(curr);
                s.emplace(ans);
            }
        }
        for(int i=1;i<arm.size();i++) {
            adj[arm[i]].emplace_back(arm[i-1]);
            adj[arm[i-1]].emplace_back(arm[i]);
            Answer(arm[i],arm[i-1]);
        }
        vector<int> order;
        function<void(int,int)> dfs = [&](int x,int p) {
            order.emplace_back(x);
            for(int&i:adj[x])if(i!=p)dfs(i,x);
        };
        dfs(0,-1);
        function check = [&](int x) {
            for(int i=0;i<x;i++)Place[order[i]]=true;
            Place[arm[0]]=true;
            assert(arm[0]>0);
            bool ans = Ask(0,arm[0],Place);
            for(int i=0;i<N;i++)Place[i]=false;
            return !ans;
        };
        int ans = 0;
        for(int jump=1024;jump;jump/=2) {
            if(ans+jump>=order.size())continue;
            if(check(ans+jump))ans+=jump;
        }
        adj[order[ans]].emplace_back(arm[0]);
        adj[arm[0]].emplace_back(order[ans]);
        Answer(arm[0],order[ans]);
    }
}

void Detect(int T, int N) {
    if(T==1)strat1(N);
    else stratTree(N);
}

Compilation message

park.cpp: In function 'void stratTree(int)':
park.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int i=1;i<arm.size();i++) {
      |                     ~^~~~~~~~~~~
park.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             if(ans+jump>=order.size())continue;
      |                ~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 4 ms 464 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 604 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -