Submission #315216

# Submission time Handle Problem Language Result Execution time Memory
315216 2020-10-22T04:50:43 Z daniel920712 CONSUL (info1cup19_consul) C++14
100 / 100
38 ms 384 KB
#include "grader.h"
#include "grader.h"
#include <map>
#include <time.h>
#include <algorithm>
using namespace std;
map < int , int > all;
int how[1005];
void solve(int n)
{
    srand(time(NULL));
    all.clear();
    int i,t,big=0,xx=n,x,y;
    if(n<=50)
    {
        for(i=1;i<=n;i++)
        {
            t=kth(i);
            all[t]++;
            big=max(big,all[t]);
 
            if(all[t]>n/3)
            {
                say_answer(t);
                return;
            }
            if(big+(n-i)<=n/3)
            {
                say_answer(-1);
                return;
            }
        }
        say_answer(-1);
    }
    else
    {
        for(i=0;i<n;i++) how[i]=i+1;
        random_shuffle(how,how+n);
        for(i=0;i<30;i++)
        {
            x=kth(how[i]);
            if(cnt(x)>n/3)
            {
                say_answer(x);
                return;
            }
 
        }
        say_answer(-1);
    }
 
}

Compilation message

consul.cpp: In function 'void solve(int)':
consul.cpp:13:19: warning: unused variable 'xx' [-Wunused-variable]
   13 |     int i,t,big=0,xx=n,x,y;
      |                   ^~
consul.cpp:13:26: warning: unused variable 'y' [-Wunused-variable]
   13 |     int i,t,big=0,xx=n,x,y;
      |                          ^
# Verdict Execution time Memory Grader output
1 Correct 37 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 256 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 360 KB Output is correct
2 Correct 26 ms 256 KB Output is correct
3 Correct 9 ms 256 KB Output is correct
4 Correct 8 ms 256 KB Output is correct
5 Correct 30 ms 256 KB Output is correct
6 Correct 35 ms 256 KB Output is correct
7 Correct 33 ms 384 KB Output is correct
8 Correct 27 ms 256 KB Output is correct
9 Correct 27 ms 256 KB Output is correct
10 Correct 35 ms 256 KB Output is correct
11 Correct 30 ms 256 KB Output is correct
12 Correct 22 ms 256 KB Output is correct
13 Correct 38 ms 256 KB Output is correct
14 Correct 26 ms 256 KB Output is correct