#include "minerals.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
constexpr int MAX_N = 43000;
constexpr int MAX_CALLS = 1000000;
namespace {
void WrongAnswer(int code) {
printf("Wrong Answer [%d]\n", code);
exit(0);
}
int N;
int counterpart[2 * MAX_N + 1];
int num_queries;
int num_kinds;
int on[2 * MAX_N + 1];
int count[2 * MAX_N + 1];
int num_answers;
int answer[2 * MAX_N + 1];
} // namespace
int Query(int x) {
if (!(1 <= x && x <= 2 * N)) {
WrongAnswer(1);
}
if (++num_queries > MAX_CALLS) {
WrongAnswer(2);
}
const int type = std::min(x, counterpart[x]);
if (on[x]) {
--on[x];
--count[type];
if (count[type] == 0) {
--num_kinds;
}
} else {
++on[x];
++count[type];
if (count[type] == 1) {
++num_kinds;
}
}
return num_kinds;
}
void Answer(int a, int b) {
if (++num_answers > N) {
WrongAnswer(6);
}
if (!(1 <= a && a <= 2 * N && 1 <= b && b <= 2 * N)) {
WrongAnswer(3);
}
if (answer[a] != 0) {
WrongAnswer(4);
}
answer[a] = b;
if (answer[b] != 0) {
WrongAnswer(4);
}
answer[b] = a;
if (!(counterpart[a] == b && counterpart[b] == a)) {
WrongAnswer(5);
}
}
#include<bits/stdc++.h>
using namespace std;
void print(vector<vector<int> >v)
{
puts("start");
for(auto p:v)
{
for(auto q:p)printf("%d ", q);
puts("");
}
puts("end");
}
#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>A;
vector<vector<int> >v;
int a;
void solve()
{
bool flag=true;
for(int i=0;i<v.size();i++)if(v[i].size()>=2)flag=false;
if(flag)return;
int sz=0;
for(int i=0;i<v.size();i++)
{
if(i%2==0)
{
for(int j=sz+(v[i].size()+1)/2;j<sz+v[i].size();j++)a=Query(A[j]);
}
else
{
for(int j=sz;j<sz+(v[i].size()+1)/2;j++)a=Query(A[j]);
}
sz+=v[i].size();
}
vector<vector<int> >V;
for(int i=0;i<v.size();i++)
{
vector<int>Fi, Se;
for(auto p:v[i])
{
int b=Query(p);
if(a!=b)Se.push_back(p);
else Fi.push_back(p);
a=b;
}
V.push_back(Fi);
V.push_back(Se);
}
v=V;
solve();
}
void Solve(int N)
{
vector<int>A, B;
for(int i=1;i<=2*N;i++)
{
int b=Query(i);
if(a!=b)A.push_back(i);
else B.push_back(i);
a=b;
}
::A=A;
v={B};
solve();
vector<int>ans;
for(int i=0;i<v.size();i++)if(v[i].size())ans.push_back(v[i][0]);
for(int i=0;i<N;i++)Answer(A[i], ans[i]);
}
int main() {
if (scanf("%d", &N) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
for (int i = 1; i <= N; ++i) {
int x, y;
if (scanf("%d%d", &x, &y) != 2) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
counterpart[x] = y;
counterpart[y] = x;
}
Solve(N);
if (num_answers != N) {
WrongAnswer(6);
}
printf("Accepted: %d\n", num_queries);
return 0;
}
Compilation message
minerals.cpp: In function 'void solve()':
minerals.cpp:93:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i=0;i<v.size();i++)if(v[i].size()>=2)flag=false;
| ~^~~~~~~~~
minerals.cpp:96:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
minerals.cpp:100:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int j=sz+(v[i].size()+1)/2;j<sz+v[i].size();j++)a=Query(A[j]);
| ~^~~~~~~~~~~~~~~
minerals.cpp:104:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int j=sz;j<sz+(v[i].size()+1)/2;j++)a=Query(A[j]);
| ~^~~~~~~~~~~~~~~~~~~~~
minerals.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:139:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int i=0;i<v.size();i++)if(v[i].size())ans.push_back(v[i][0]);
| ~^~~~~~~~~
/usr/bin/ld: /tmp/ccz16pCc.o: in function `Query(int)':
grader.cpp:(.text+0x30): multiple definition of `Query(int)'; /tmp/ccV9oMpf.o:minerals.cpp:(.text+0x180): first defined here
/usr/bin/ld: /tmp/ccz16pCc.o: in function `Answer(int, int)':
grader.cpp:(.text+0x100): multiple definition of `Answer(int, int)'; /tmp/ccV9oMpf.o:minerals.cpp:(.text+0x250): first defined here
/usr/bin/ld: /tmp/ccz16pCc.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccV9oMpf.o:minerals.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status