This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dango3.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
ll n,m;
vector<vii>ans;
bool vis[100000];
bool viss[5001];
ll query(vii &v){
vii q;
memset(viss,1,sizeof viss);
for(int i=0;i<v.size();i++){
viss[v[i]]&=vis[i];
}
for(int i=1;i<=n*m;i++){
if(viss[i])
q.pb(i);
}
return Query(q);
}
void s(ll x,vii v){
for(int i=0;i<v.size();i++)
vis[i]=1;
if(x==1){
ans.pb(v);
return;
}
vii vl,vr;
ll cnt=0;
ll last=m;
for(int i=0;i<v.size();i++){
if(cnt==x/2){
vis[i]=0;
ll res=query(v);
if(res==m-2)
vl.pb(v[i]);
else
vr.pb(v[i]);
vis[i]=1;
continue;
}
vl.pb(v[i]);
vis[i]=0;
ll res=query(v);
if(res<last&&i>0)
vis[i]=1;
else
cnt++,last=res;
}
s(x/2,vl),s((x+1)/2,vr);
}
void Solve(int N, int M) {
n=N,m=M;
vii v;
for(int i=1;i<=n*m;i++)
v.pb(i);
s(n,v);
v.clear();
for(int i=0;i<m;i++){
v.clear();
for(auto it:ans)
v.pb(it[i]);
Answer(v);
}
}
Compilation message (stderr)
dango3.cpp: In function 'll query(vii&)':
dango3.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
dango3.cpp: In function 'void s(ll, vii)':
dango3.cpp:28:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
dango3.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |