답안 #581866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581866 2022-06-23T07:32:42 Z Abdulmohsen1284 도서관 (JOI18_library) C++14
19 / 100
471 ms 424 KB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
long long s=0;
vector <int> em;
void rec(long long cur,vector <int> grp)
{
    
    long long fr=Query(grp);
    grp[cur-1]=1;
    if(fr==Query(grp))
    {
        long long sum=0;
        grp[cur-1]=0;
        for(int i=0;i<grp.size();i++)
        {
            if(grp[i]==1)
                sum++;
        }
        if(sum==1)
        {
            for(int i=0;i<grp.size();i++)
            {
            if(grp[i]==1)
                s=i+1;
            }
            
            return;
        }
        if(s==0)
            Answer(em);
        vector <int> on=em,tw=em;
        long long took=0;
        for(int i=0;took<sum/2;i++)
        {
            if(i>=grp.size())
                break;
            if(grp[i]==1)
            {
                took++;
                on[i]=grp[i];
            }
        }
        for(int i=0;i<grp.size();i++)
        {
            if((grp[i]^on[i])==1)
                tw[i]=1;
        }
        for(int i=0;i<on.size();i++)
        {
            if(on[i]==1)
            {
                rec(cur,on);
                break;
            }
        }
        for(int i=0;i<tw.size();i++)
        {
            if(tw[i]==1)
            {
                rec(cur,tw);
                return;
            }
        }
        
    }
    else
        return;
}

void Solve(int N)
{
    if(N==1)
    {
        em.push_back(1);
        Answer(em);
        return;
    }
    for(int i=1;i<=N;i++)
        em.push_back(0);
    for(int i=1;i<=N;i++)
    {
        vector <int> ask=em;
        for(int j=1;j<=N;j++)
        {
            if(i==j)
                continue;
            ask[j-1]=1;
        }
        long long ans=Query(ask);
        if(ans==1)
        {
            s=i;
            break;
        }
    }
    vector <int> ret,lef=em;
    ret.push_back(s);
    for(int i=1;i<=N;i++)
    {
        if(s==i)
            continue;
        lef[i-1]=1;
    }
    for(int i=1;i<N;i++)
    {
        rec(s,lef);
        ret.push_back(s);
        lef[s-1]=0;
    }
    
    Answer(ret);
}

Compilation message

library.cpp: In function 'void rec(long long int, std::vector<int>)':
library.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for(int i=0;i<grp.size();i++)
      |                     ~^~~~~~~~~~~
library.cpp:23:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             for(int i=0;i<grp.size();i++)
      |                         ~^~~~~~~~~~~
library.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             if(i>=grp.size())
      |                ~^~~~~~~~~~~~
library.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int i=0;i<grp.size();i++)
      |                     ~^~~~~~~~~~~
library.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int i=0;i<on.size();i++)
      |                     ~^~~~~~~~~~
library.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int i=0;i<tw.size();i++)
      |                     ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 208 KB # of queries: 5115
2 Correct 66 ms 208 KB # of queries: 5129
3 Correct 81 ms 304 KB # of queries: 5552
4 Correct 84 ms 308 KB # of queries: 5497
5 Correct 65 ms 336 KB # of queries: 5408
6 Correct 80 ms 300 KB # of queries: 5447
7 Correct 90 ms 208 KB # of queries: 5424
8 Correct 74 ms 208 KB # of queries: 5196
9 Correct 78 ms 296 KB # of queries: 5436
10 Correct 35 ms 208 KB # of queries: 3170
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 3
13 Correct 1 ms 208 KB # of queries: 10
14 Correct 1 ms 208 KB # of queries: 19
15 Correct 3 ms 208 KB # of queries: 181
16 Correct 7 ms 208 KB # of queries: 409
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 208 KB # of queries: 5115
2 Correct 66 ms 208 KB # of queries: 5129
3 Correct 81 ms 304 KB # of queries: 5552
4 Correct 84 ms 308 KB # of queries: 5497
5 Correct 65 ms 336 KB # of queries: 5408
6 Correct 80 ms 300 KB # of queries: 5447
7 Correct 90 ms 208 KB # of queries: 5424
8 Correct 74 ms 208 KB # of queries: 5196
9 Correct 78 ms 296 KB # of queries: 5436
10 Correct 35 ms 208 KB # of queries: 3170
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 3
13 Correct 1 ms 208 KB # of queries: 10
14 Correct 1 ms 208 KB # of queries: 19
15 Correct 3 ms 208 KB # of queries: 181
16 Correct 7 ms 208 KB # of queries: 409
17 Runtime error 471 ms 424 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -