# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
383246 | Ahmad_Hasan | CONSUL (info1cup19_consul) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "grader.h"
/**
|||||||||| ||||| ||||| ||||||||||
||||||||||||| ||||| ||||| |||||
|||| |||||| ||||| ||||| |||||
||||||||||||||||| ||||||||||||||| ||||||||||
||||||||||||||||||| ||||||||||||||| |||||
||||| ||||| ||||| ||||| |||||
||||| ||||| ||||| ||||| ||||||||||
AHMED;HASSAN;SAEED;
*/
using namespace std;
static const int MIN_VALUE = 0, MAX_VALUE = (1e9) - 1;
static map<int,int> mp;
static int Q, N, a[5005];
static bool issol, answer;
void solve(int n){
vector<int>vis(n);
for(int i=0;i<min(30,n/2);i++){
int ri=rand()%n;
while(vis[ri]){
ri=rand()%n;
}
vis[ri]=1;
int ret=kth(ri+1);
int ret2=cnt(ret);
if(ret2>((n)/3)){
say_answer(ret);
return;
}
}
say_answer(-1);
}
void say_answer(int k)
{
cout<<k<<'\n';
if(answer)
{
cout << "Multiple answers provided for the same testcase!\n";
exit(0);
}
answer = 1;
if(k == -1)
{
if(issol)
{
cout << "Wrong answer\n";
exit(0);
}
else cout << "Correct! Number of queries: " << Q << '\n';
}
else
{
if(!issol || mp[k] <= N/3)
{
cout << "Wrong answer\n";
exit(0);
}
else cout << "Correct! Number of queries: " << Q << '\n';
}
}
int cnt(int k)
{
++Q;
if(!(k>=MIN_VALUE && k<=MAX_VALUE))
{
cout << "Wrong query format\n";
exit(0);
}
return mp[k];
}
int kth(int k)
{
++Q;
if(!(k>=1 && k<=N))
{
cout << "Wrong query format\n";
exit(0);
}
return a[k];
}
int main()
{
int tests, i;
cin >> tests;
while(tests--)
{
cin >> N; mp.clear();
Q = 0; issol = 0; answer = 0;
for(i=1; i<=N; ++i) cin >> a[i], ++mp[a[i]];
for(i=1; i<=N; ++i) issol |= (mp[a[i]] > N/3);
solve(N);
}
return 0;
}