QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649166 | #6439. Cloud Retainer's Game | inoader | TL | 0ms | 3632kb | C++14 | 1.7kb | 2024-10-17 21:56:00 | 2024-10-17 21:56:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
int x=0,k=1;char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')k=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*k;
}
void sol(){
int h=read();
int n=read();
map<int,vector<int>>a,b;
for(int i=1;i<=n;++i){
int x=read(),y=read();
b[(x%(2*h)+y)%(2*h)].push_back(x);
if((x%(2*h)+y)%(2*h)!=(x%(2*h)+2*h-y)%(2*h))b[(x%(2*h)+2*h-y)%(2*h)].push_back(x);
}
int m=read();
for(int i=1;i<=m;++i){
int x=read(),y=read();
a[(x%(2*h)+y)%(2*h)].push_back(x);
if((x%(2*h)+y)%(2*h)!=(x%(2*h)+2*h-y)%(2*h))a[(x%(2*h)+2*h-y)%(2*h)].push_back(x);
}
for(auto &it:a)sort(it.second.begin(),it.second.end());
for(auto &it:b)sort(it.second.begin(),it.second.end());
int ans=0;
queue<pair<int,int>>q;
q.push({0,0});
map<int,map<int,int>>f;
set<pair<int,int>>se;
se.insert({0,0});
while(!q.empty()){
int k=q.front().first,x=q.front().second;
q.pop();
se.erase({k,x});
int c=a[k].end()-upper_bound(a[k].begin(),a[k].end(),x);
ans=max(ans,f[k][x]+c);
auto it=upper_bound(b[k].begin(),b[k].end(),x);
if(it==b[k].end())continue;
int cc=a[k].end()-upper_bound(a[k].begin(),a[k].end(),*it);
int kk=k;
int y=(*it-k)%(2*h);
if(y>h)y=2*h-y;
if((*it-k)%(2*h)>h){
kk=(*it%(2*h)+2*h-y)%(2*h);
}
else kk=(*it%(2*h)+y)%(2*h);
if(!f.count(kk)||f[kk].count(*it)||f[kk][*it]<f[k][x]+c-cc){
f[kk][*it]=f[k][x]+c-cc;
if(se.count({kk,*it}))continue;
se.insert({kk,*it});
q.push({kk,*it});
}
q.push({k,*it});
}
cout<<ans<<endl;
}
signed main(){
int T=read();
while(T--)sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
2 4 3 1 1 2 2 6 2 4 3 1 3 3 5 1 7 3 3 1 4 2 3 1 1 6 2 9 1
output:
3 3
result:
ok 2 number(s): "3 3"
Test #2:
score: -100
Time Limit Exceeded
input:
5503 10 19 2 4 2 8 8 3 8 4 8 7 2 7 2 6 1 5 3 2 6 4 2 1 4 5 2 5 7 1 4 7 5 7 2 2 8 6 8 1 12 5 1 4 8 5 2 6 1 3 6 1 1 1 7 7 2 5 6 6 8 1 2 3 5 10 5 9 5 10 7 6 6 5 7 1 3 9 6 8 8 8 6 4 2 9 5 4 4 2 10 9 2 3 2 1 7 1 4 3 14 4 6 6 1 2 1 7 6 2 3 4 4 5 3 6 5 1 4 3 4 3 2 6 2 8 6 8 2 6 6 5 2 5 1 3 1 2 3 7 4 5 5 3 ...
output:
2 1 2 1 3 2 0 2 4 6 1 2 0 0 1 2 1 1 0 1 0 0 2 1 1 3 2 3 3 2 1 2 0 1 5 1 1 1 0 1 3 1 2 3 3 3 2 1 0 3 1 2 2 0 3 1 1 0 1 2 2 2 1 1 1 1 2 3 2 2 2 1 1 3 1 3 0 0 3 4 5 1 1 1 1 1 0 2 0 0 3 0 2 1 1 1 0 3 2 1 3 4 3 2 2 4 2 4 2 1 2 1 0 1 3 0 3 0 2 1 0 2 4 1 2 1 1 0 1 3 0 2 3 1 4 2 2 0 2 3 2 0 0 3 1 1 1 1 3 2 ...