QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22319#2356. Partition of QueriesWhybullYMe#WA 5ms12080kbC++141.5kb2022-03-09 15:08:392022-04-30 00:53:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 00:53:30]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:12080kb
  • [2022-03-09 15:08:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ri int
typedef long long ll;
const int maxn=1e6+10;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
template<class T>inline void clear(T *arr,int siz,int val=0){memset(arr,val,sizeof(T)*(siz+1));}
template<typename T>
struct dq{
	int hd,tl;
	T v[maxn];
	inline dq(){hd=1;}
	inline T front(int ex=0){return v[hd+ex];}
	inline T back(int ex=0){return v[tl-ex];}
	inline void pop_front(){++hd;}
	inline void pop_back(){--tl;}
	inline void push(T k){v[++tl]=k;}
	inline int size(){return tl-hd+1;}
	inline void clear(){hd=1,tl=0;}
};
dq<int>q;
int a[maxn],m,n,tot;
char s[maxn];
ll ans,f[maxn],suf[maxn],suf2[maxn];
inline ll K(int k){return n-k+1;}
inline ll X(int k){return suf[k+1];}
inline ll Y(int k){return f[k]+suf2[k+1];}
inline double slope(int u,int v){return 1.*(Y(v)-Y(u))/(X(v)-X(u));}
int main(){
	scanf("%d%d%s",&n,&m,s+1);
	for(ri i=1,j=0;i<=n;++i){
		if(s[i]=='?')a[++tot]=j,j=0;
		else ++j;
	}
	n=tot;
	for(ri i=n;i;--i){
		suf[i]=suf[i+1]+a[i];
		suf2[i]=suf2[i+1]+1ll*a[i]*(n-i+1);
	}
	ans=suf2[1];
	q.push(0);
	for(ri i=1;i<=n;++i){
		while(q.size()>1&&slope(q.front(1),q.front())>K(i))q.pop_front();
		ri j=q.front();
		f[i]=f[j]+suf2[j+1]-suf2[i]-(n-i+1)*(suf[j+1]-suf[i])+m;
		ckmin(ans,f[i]+suf2[i+1]);
		while(q.size()>1&&slope(q.back(),q.back(1))<slope(i,q.back()))q.pop_back();
		q.push(i);
	}
	printf("%lld",ans);
	return 0;
}

詳細信息

Test #1:

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

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

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

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 1ms
memory: 9828kb

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 12040kb

input:

10 0
++?+??++??

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 3ms
memory: 11880kb

input:

12 100
+?+++??+??++

output:

19

result:

ok single line: '19'

Test #6:

score: 0
Accepted
time: 4ms
memory: 11948kb

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 3ms
memory: 11952kb

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 5ms
memory: 11944kb

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 5ms
memory: 11880kb

input:

10 15
++++++++??

output:

15

result:

ok single line: '15'

Test #10:

score: 0
Accepted
time: 5ms
memory: 12004kb

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 3ms
memory: 11980kb

input:

10 5
+?+?+??+??

output:

10

result:

ok single line: '10'

Test #12:

score: 0
Accepted
time: 3ms
memory: 11948kb

input:

10 7
+?+?+??+??

output:

12

result:

ok single line: '12'

Test #13:

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

input:

15 4
+?+?+??+??+??+?

output:

14

result:

ok single line: '14'

Test #14:

score: 0
Accepted
time: 4ms
memory: 11980kb

input:

15 6
+?+?+??+??+??+?

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 3ms
memory: 12040kb

input:

19 8
+?+?+??+??+??+?++??

output:

28

result:

ok single line: '28'

Test #16:

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

input:

20 9
+?+?+??+??+??+?++???

output:

30

result:

ok single line: '30'

Test #17:

score: 0
Accepted
time: 1ms
memory: 11952kb

input:

500 100
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++++...

output:

2710

result:

ok single line: '2710'

Test #18:

score: -100
Wrong Answer
time: 2ms
memory: 12080kb

input:

10000 100
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++...

output:

2451419

result:

wrong answer 1st lines differ - expected: '56616', found: '2451419'