QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765698#2152. Paired Upnullptr_qwq100 ✓63ms171440kbC++145.9kb2024-11-20 15:01:522024-11-20 15:01:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 15:01:53]
  • 评测
  • 测评结果:100
  • 用时:63ms
  • 内存:171440kb
  • [2024-11-20 15:01:52]
  • 提交

answer

// Problem: #3575. 「USACO 2021.12 Platinum」Paired Up
// Contest: LibreOJ
// URL: https://loj.ac/p/3575
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// Author: nullptr_qwq
// 
// Powered by CP Editor (https://cpeditor.org)

// 私は猫です

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
ll read(){
	ll 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<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=5005;
int pa[maxn],va[maxn],pb[maxn],vb[maxn],n,m,N,typ,k,to[maxn][maxn],ta[maxn],tb[maxn];
ll f[maxn][maxn],g[maxn][maxn];
void solve(){
	cin>>typ>>N>>k;
	F(i,1,N){
		char op; cin>>op;
		if(op=='G')++n,cin>>pa[n]>>va[n],va[n]*=((typ==1)?(-1):1);
		else ++m,cin>>pb[m]>>vb[m],vb[m]*=((typ==1)?(-1):1);
	}
	dF(i,n,1)dF(j,m,1)to[i][j]=(abs(pa[i]-pb[j])<=k)?to[i+1][j+1]+1:0;
	F(i,0,n)F(j,0,m)f[i][j]=g[i][j]=-infll;
	int p=1,q=1;
	F(i,1,n){
		for(;p<=m&&(abs(pa[i]-pb[p])<=k||pb[p]<pa[i]);++p);
		ta[i]=p;
	}
	F(i,1,m){
		for(;q<=n&&(abs(pa[q]-pb[i])<=k||pa[q]<pb[i]);++q);
		tb[i]=q;
	}
	f[0][0]=g[0][0]=0;
	F(i,0,n)F(j,0,m){
		const int l1=max(ta[i]-j-1,0),l2=max(tb[j]-i-1,0);
		if(i+l1<=n&&to[i+1][j+1]>=l1)chkmax(g[i+l1][j+l1],f[i][j]);
		if(j+l2<=m&&to[i+1][j+1]>=l2)chkmax(f[i+l2][j+l2],g[i][j]);
		if(i<n&&j<m&&abs(pa[i+1]-pb[j+1])<=k)chkmax(f[i+1][j+1],f[i][j]),chkmax(g[i+1][j+1],g[i][j]);
		if(i<n)chkmax(f[i+1][j],f[i][j]+va[i+1]);
		if(j<m)chkmax(g[i][j+1],g[i][j]+vb[j+1]);
	}
	cout<<abs(max(f[n][m],g[n][m]));
}
signed main(){
	// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int zsy=1;
	F(____,1,zsy)solve();
}

详细


Pretests


Final Tests

Test #1:

score: 4.54545
Accepted
time: 1ms
memory: 5708kb

input:

2 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9

output:

16

result:

ok 1 number(s): "16"

Test #2:

score: 4.54545
Accepted
time: 1ms
memory: 5640kb

input:

1 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 4.54545
Accepted
time: 1ms
memory: 7800kb

input:

2 10 76
H 1 18
H 18 465
H 25 278
H 30 291
H 36 202
G 45 96
G 60 375
G 93 941
G 96 870
G 98 540

output:

1893

result:

ok 1 number(s): "1893"

Test #4:

score: 4.54545
Accepted
time: 35ms
memory: 157072kb

input:

1 4798 39810
G 0 99996
G 39809 99996
H 79621 99995
G 119433 99993
G 159245 99994
H 199057 99995
G 238866 99990
G 278675 99995
H 318485 99994
G 358296 99993
H 398107 99991
G 437918 99991
G 477730 99995
H 517539 99990
H 557349 99999
G 597159 99996
H 636970 100000
H 676779 99995
H 716589 99999
H 756399...

output:

11663453

result:

ok 1 number(s): "11663453"

Test #5:

score: 4.54545
Accepted
time: 40ms
memory: 167280kb

input:

1 4992 316227
H 0 100000
H 316227 99999
G 632455 99997
G 948681 99998
H 1264909 99990
H 1581137 99990
G 1897366 99999
H 2213593 99997
H 2529822 99997
H 2846051 99999
G 3162279 99992
H 3478507 99999
H 3794733 99996
H 4110960 99994
H 4427188 99997
H 4743417 99994
G 5059644 99992
H 5375870 99993
G 5692...

output:

9962130

result:

ok 1 number(s): "9962130"

Test #6:

score: 4.54545
Accepted
time: 56ms
memory: 152944kb

input:

1 4798 23441
H 0 100000
G 23442 99993
G 46882 99997
H 70324 99993
H 93765 99991
H 117208 99995
G 140651 100000
H 164093 99999
H 187533 99997
G 210976 99995
G 234418 99994
G 257861 99994
G 281304 99996
H 304746 99999
H 328188 99996
H 351631 99991
G 375074 99995
H 398517 99997
H 421959 99999
G 445402 ...

output:

12452011

result:

ok 1 number(s): "12452011"

Test #7:

score: 4.54545
Accepted
time: 31ms
memory: 157464kb

input:

1 4798 120225
H 0 99995
H 120227 99992
H 240452 99992
G 360678 99997
H 480903 99991
G 601127 99994
G 721351 99990
G 841575 99995
G 961801 99992
H 1082027 99996
H 1202253 99991
G 1322477 99993
G 1442704 99996
H 1562928 99990
G 1683153 99997
H 1803378 99990
G 1923603 99992
G 2043828 100000
G 2164053 9...

output:

11559649

result:

ok 1 number(s): "11559649"

Test #8:

score: 4.54545
Accepted
time: 0ms
memory: 17988kb

input:

2 262 331130
H 0 100000
G 331129 99990
G 662261 99998
G 993391 100000
H 1324522 99991
H 1655652 99994
G 1986784 99994
H 2317916 99993
G 2649046 99992
H 2980176 99994
H 3311307 99992
G 3642438 99990
G 3973567 99999
H 4304699 99999
G 4635829 99990
H 4966960 99999
G 5298092 99993
G 5629222 99993
H 5960...

output:

4169623

result:

ok 1 number(s): "4169623"

Test #9:

score: 4.54545
Accepted
time: 5ms
memory: 22200kb

input:

2 296 309029
G 0 100000
H 309030 99996
H 618061 99990
H 927089 99995
H 1236117 99993
H 1545147 100000
H 1854176 99992
H 2163206 99998
G 2472237 99993
H 2781266 99996
G 3090295 99992
H 3399326 99994
G 3708357 99990
H 4017388 99997
H 4326418 99998
G 4635447 99990
G 4944476 99999
G 5253505 99995
H 5562...

output:

5081675

result:

ok 1 number(s): "5081675"

Test #10:

score: 4.54545
Accepted
time: 0ms
memory: 20192kb

input:

2 296 10714
G 0 99996
G 10714 99997
G 21428 99991
H 32144 99992
G 42860 99996
G 53576 99990
H 64290 99997
G 75004 99992
G 85720 99991
H 96435 99992
H 107149 99995
G 117863 100000
H 128579 100000
G 139292 99994
H 150007 99997
G 160722 99991
G 171438 100000
G 182153 99990
G 192868 99990
H 203584 99999...

output:

5209978

result:

ok 1 number(s): "5209978"

Test #11:

score: 4.54545
Accepted
time: 0ms
memory: 22088kb

input:

2 262 398106
G 0 99991
H 398105 99992
G 796210 99998
H 1194316 99992
G 1592424 99999
G 1990529 99991
G 2388636 99995
G 2786743 99994
H 3184849 100000
G 3582957 99994
G 3981063 99996
H 4379169 99990
G 4777277 99992
G 5175383 99990
G 5573489 99991
G 5971596 99996
G 6369702 99997
H 6767810 99996
H 7165...

output:

5526428

result:

ok 1 number(s): "5526428"

Test #12:

score: 4.54545
Accepted
time: 0ms
memory: 20232kb

input:

2 262 2290
G 0 99993
G 2292 99990
H 4583 99994
G 6873 99999
G 9162 99996
H 11452 100000
H 13743 99997
H 16032 99993
H 18322 99994
G 20611 99997
G 22901 99998
G 25193 99997
G 27485 100000
H 29775 99991
G 32065 99991
H 34357 99992
G 36649 99996
H 38941 99992
G 41230 99992
G 43519 99995
G 45808 99997
H...

output:

3844153

result:

ok 1 number(s): "3844153"

Test #13:

score: 4.54545
Accepted
time: 0ms
memory: 22044kb

input:

2 262 954992
H 0 99990
H 954993 99994
G 1909986 99993
H 2864979 99995
H 3819971 99991
H 4774965 99996
H 5729957 99994
G 6684949 99998
H 7639940 99998
G 8594933 99991
H 9549925 99997
H 10504919 99997
G 11459913 100000
H 12414904 99994
G 13369897 99992
H 14324890 99994
H 15279881 99990
H 16234872 9999...

output:

4560955

result:

ok 1 number(s): "4560955"

Test #14:

score: 4.54545
Accepted
time: 0ms
memory: 20208kb

input:

2 262 346736
H 0 99993
G 346736 99995
H 693472 99992
H 1040208 99997
G 1386945 99993
G 1733681 99992
H 2080417 99995
H 2427154 99996
H 2773892 99994
G 3120628 99995
H 3467364 100000
G 3814100 100000
H 4160835 99991
G 4507573 99990
G 4854310 99999
H 5201046 99992
H 5547783 99992
H 5894521 99990
G 624...

output:

5212186

result:

ok 1 number(s): "5212186"

Test #15:

score: 4.54545
Accepted
time: 48ms
memory: 152204kb

input:

2 4798 2753
H 0 99990
H 2752 99999
H 5504 99991
G 8259 99990
H 11012 100000
G 13765 99998
H 16518 99997
H 19270 99991
G 22023 99997
H 24775 100000
G 27528 99993
H 30281 99999
G 33033 99997
G 35786 100000
H 38539 99996
H 41291 99993
H 44043 99999
G 46797 99994
H 49549 99993
H 52301 99992
G 55055 9999...

output:

16311936

result:

ok 1 number(s): "16311936"

Test #16:

score: 4.54545
Accepted
time: 51ms
memory: 154104kb

input:

2 4798 69182
H 0 99996
G 69184 99996
G 138367 99997
G 207551 99991
H 276733 99990
H 345914 100000
H 415097 99998
H 484281 100000
G 553464 99991
H 622648 99991
H 691830 99996
G 761014 99993
H 830198 99996
H 899380 99993
H 968562 99997
G 1037746 99990
H 1106929 99996
G 1176111 99996
G 1245293 99991
G ...

output:

16104701

result:

ok 1 number(s): "16104701"

Test #17:

score: 4.54545
Accepted
time: 63ms
memory: 162488kb

input:

2 4995 131825
G 0 100000
G 131826 99991
G 263652 99996
G 395476 99995
G 527300 99998
H 659124 99999
H 790950 99997
H 922777 99994
G 1054604 99996
G 1186428 99995
G 1318255 99990
G 1450080 99999
H 1581907 100000
G 1713731 99991
G 1845558 100000
H 1977383 99991
G 2109208 99999
H 2241034 100000
H 23728...

output:

16952402

result:

ok 1 number(s): "16952402"

Test #18:

score: 4.54545
Accepted
time: 54ms
memory: 155820kb

input:

2 4798 1777
G 0 99991
H 1777 99999
H 3553 99998
G 5332 99997
G 7111 99997
G 8888 100000
H 10666 99996
G 12442 99991
G 14218 99998
G 15997 99997
G 17775 99998
H 19553 99992
G 21329 99991
H 23108 99998
G 24887 99991
H 26665 99997
G 28444 99997
H 30221 99997
G 32000 99991
H 33776 99994
H 35555 99997
H ...

output:

15520928

result:

ok 1 number(s): "15520928"

Test #19:

score: 4.54545
Accepted
time: 44ms
memory: 171440kb

input:

2 4998 123026
G 0 99998
G 123025 99993
H 246050 99995
H 369077 99996
G 492105 99994
G 615132 99996
H 738158 99990
G 861185 99997
H 984212 99996
H 1107239 99991
H 1230267 99996
G 1353295 100000
H 1476320 99994
H 1599346 99994
H 1722374 99992
H 1845402 99995
G 1968428 99996
G 2091453 99999
H 2214478 9...

output:

14687130

result:

ok 1 number(s): "14687130"

Test #20:

score: 4.54545
Accepted
time: 39ms
memory: 166948kb

input:

2 4999 13489
G 0 99993
H 13491 99995
G 26982 99998
H 40471 99991
G 53959 99996
H 67450 99991
H 80939 99991
H 94428 99996
H 107917 99990
H 121406 99995
H 134897 99994
H 148386 99998
G 161877 99995
G 175367 99997
H 188858 99997
H 202346 99998
G 215837 99992
G 229328 99995
G 242817 99993
G 256308 99991...

output:

16915188

result:

ok 1 number(s): "16915188"

Test #21:

score: 4.54545
Accepted
time: 43ms
memory: 169044kb

input:

2 4998 47862
H 0 99991
G 47863 99995
H 95726 99993
G 143589 100000
H 191450 99993
H 239312 99997
H 287175 99991
G 335039 99999
H 382903 99996
H 430767 99999
G 478630 99998
G 526491 99993
H 574355 99998
G 622219 99993
H 670080 99993
G 717943 99992
G 765804 99992
G 813668 99990
H 861532 99993
G 909393...

output:

15378747

result:

ok 1 number(s): "15378747"

Test #22:

score: 4.54545
Accepted
time: 53ms
memory: 167556kb

input:

2 4995 3547
H 0 99996
H 3547 99995
G 7093 99996
G 10640 99990
H 14188 99991
G 17734 99998
H 21281 99995
H 24830 99996
H 28376 99992
H 31925 99997
G 35474 99994
H 39023 99997
G 42572 99998
H 46118 99999
H 49664 100000
G 53211 99991
H 56759 99999
G 60305 99997
G 63853 99994
H 67400 99993
G 70947 99990...

output:

13515640

result:

ok 1 number(s): "13515640"