QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292206#7950. Lucky DrawsPhantomThreshold#WA 175ms486764kbC++171.4kb2023-12-27 20:27:492023-12-27 20:27:49

Judging History

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

  • [2023-12-27 20:27:49]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:486764kb
  • [2023-12-27 20:27:49]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = 510000;

int n,K;
struct node
{
	int l,r;
}a[maxn];

int t[maxn],tp;
map<int,int>mp; int mpn;

short int num[20005][20005];

vector<int>f[maxn];

void solve(int k,int ml,int mr,int l,int r)
{
	if(l>r) return;
	int mid=(l+r)>>1;
	int mi,ma=n+1;
	for(int i=ml;i<=mr;i++) if(i<mid)
	{
		int temp= f[k-1][i]+ (int)num[i+1][mid-1];
		if(temp<ma)
		{
			ma=temp;
			mi=i;
		}
	}
	f[k][mid]=ma;
	solve(k,ml,mi,l,mid-1);
	solve(k,mi,mr,mid+1,r);
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	cin>>n>>K;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].l>>a[i].r;
		t[++tp]=a[i].l;
		t[++tp]=a[i].r;
	}
	
	sort(t+1,t+tp+1);
	for(int i=1;i<=tp;i++)
	{
		if(i==1||t[i]!=t[i-1]) mp[t[i]]=++mpn;
	}
	for(int i=1;i<=n;i++) 
	{
		a[i].l=mp[a[i].l];
		a[i].r=mp[a[i].r];
	}
	
	for(int i=1;i<=n;i++) num[a[i].l][a[i].r]++;
	for(int l=mpn;l>=1;l--)
	{
		for(int r=l;r<=mpn;r++)
		{
			num[l][r]+=num[l][r-1];
		}
		for(int r=l;r<=mpn;r++)
		{
			num[l][r]+=num[l+1][r];
		}
	}
	
	f[1].resize(mpn+5);
	for(int r=1;r<=mpn;r++)
	{
		f[1][r]=num[1][r-1];
	}
	for(int i=2;i<=K;i++)
	{
		f[i].resize(mpn+5);
		solve(i,1,mpn,1,mpn);
	}
	int ans=n;
	for(int i=K;i<=mpn;i++) ans=min(ans,f[K][i]+num[i+1][mpn]);
	cout<<n-ans<<endl;
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 21300kb

input:

5 2
1 2
1 4
3 6
4 7
5 6

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 0ms
memory: 20808kb

input:

3 2
2 4
1 3
3 5

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 0ms
memory: 20680kb

input:

4 1
2 3
1 1
4 5
4 5

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 21524kb

input:

7 2
5 6
7 9
7 7
1 4
2 3
4 7
4 7

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 120ms
memory: 408684kb

input:

10000 50
-16187 -16186
743439 743441
-995450 -995449
921242 921242
-287646 -287644
110263 110264
650110 650110
897150 897151
262837 262839
935191 935193
6079 6080
815160 815162
-624776 -624774
-782088 -782086
486051 486052
-704289 -704287
-592330 -592329
-943804 -943803
43046 43047
-896912 -896910
-...

output:

100

result:

ok single line: '100'

Test #6:

score: 0
Accepted
time: 175ms
memory: 486764kb

input:

10000 50
39778 39796
7765 7768
95957 95972
-92200 -92178
-67044 -67014
856 871
-95402 -95380
-29447 -29418
77170 77191
-50433 -50421
-18466 -18446
47582 47583
89872 89873
19175 19205
-46181 -46175
30461 30465
-83893 -83891
-87464 -87450
-92490 -92469
-95035 -95008
-60182 -60165
-9191 -9191
-61912 -6...

output:

265

result:

ok single line: '265'

Test #7:

score: -100
Wrong Answer
time: 4ms
memory: 92904kb

input:

1000 200
1255 1300
4000 4019
4062 4090
4733 4781
1597 1684
6391 6394
4958 5012
3552 3552
3136 3182
2597 2664
7296 7344
5596 5685
8676 8745
1897 1995
6009 6029
2548 2553
410 460
4985 5046
2520 2581
8270 8342
1376 1447
1317 1367
6561 6623
5059 5114
8435 8444
4773 4823
6756 6825
3674 3769
8881 8893
278...

output:

0

result:

wrong answer 1st lines differ - expected: '948', found: '0'