QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245424 | #6439. Cloud Retainer's Game | zbhruarua | AC ✓ | 997ms | 35176kb | C++20 | 2.4kb | 2023-11-09 21:48:05 | 2023-11-09 21:48:07 |
Judging History
answer
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<bitset>
#include<set>
#define ll long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define forE(i,x) for(int i=head[x];i;i=nxt[i])
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=1e6+5;
const int mod=998244353;
const int INF=1e9;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+(c-'0');
c=getchar();
}
return x*f;
}
int T;
struct node{
ll x,y,t;
}a[maxn];
map<ll,int> p[2];
signed main()
{
T=read();
while(T--)
{
p[0].clear(),p[1].clear();
ll H=read();
int n=read(),tot=0;
rep(i,1,n) a[++tot]={read(),read(),0};
int m=read();
rep(i,1,m) a[++tot]={read(),read(),1};
sort(a+1,a+tot+1,[&](node u,node v)->bool {return u.x<v.x;});
int ans=1;
p[0][0] = 1;
p[1][0] = 1;
rep(i,1,tot)
{
ll x=a[i].x,y=a[i].y,t=a[i].t;
int up = p[0][(x-y)%(2*H)];
int down = p[1][(x+y)%(2*H)];
if(up==0) up=-INF;
if(down==0) down=-INF;
ans=max(ans,max(up,down)+(t==1));
if(t==1)
{
p[0][(x-y)%(2*H)] = max(p[0][(x-y)%(2*H)],up+1);
int topx=H-y+x,topy=H;
p[1][(topx+topy)%(2*H)] = max(p[1][(topx+topy)%(2*H)],up+1);
p[1][(x+y)%(2*H)] = max(p[1][(x+y)%(2*H)],down+1);
int lowx=x+y,lowy=0;
p[0][(lowx-lowy)%(2*H)] = max(p[0][(lowx-lowy)%(2*H)],down+1);
}
else
{
int v=max(up,down);
p[0][(x-y)%(2*H)] = max(p[0][(x-y)%(2*H)],v);
int topx=H-y+x,topy=H;
p[1][(topx+topy)%(2*H)] = max(p[1][(topx+topy)%(2*H)],v);
p[1][(x+y)%(2*H)] = max(p[1][(x+y)%(2*H)],v);
int lowx=x+y,lowy=0;
p[0][(lowx-lowy)%(2*H)] = max(p[0][(lowx-lowy)%(2*H)],v);
}
}
printf("%d\n",ans-1);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 0
Accepted
time: 505ms
memory: 11252kb
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 4 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 5 1 2 2 1 0 1 3 0 2 3 1 4 2 2 0 2 3 2 0 0 3 1 1 1 1 3 2 ...
result:
ok 5503 numbers
Test #3:
score: 0
Accepted
time: 997ms
memory: 35176kb
input:
54 83 1995 54 14 42 63 23 55 46 52 94 71 16 18 51 54 62 47 90 38 42 50 82 20 8 28 52 64 49 19 56 5 10 74 99 30 90 42 48 2 11 78 4 38 78 77 26 26 47 12 82 60 41 17 87 2 37 16 51 15 32 63 88 82 76 33 44 10 94 28 31 5 30 80 29 19 35 70 88 78 39 69 40 5 84 52 87 59 54 36 34 76 88 42 42 37 79 70 27 77 19...
output:
47 32 32 32 38 32 39 33 39 40 36 32 36 32 46 30 35 41 40 36 108 90 98 81 166 115 106 170 148 113 198 72 57 202 337 153 186 978 87 886 151 489 111 112 90 154 174 188 266 59 10210 1041 87 981
result:
ok 54 numbers