QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22325#2356. Partition of QueriesDaBenZhongXiaSongKuaiDi#WA 4ms7840kbC++20977b2022-03-09 15:28:312022-04-30 00:54:04

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:54:04]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:7840kb
  • [2022-03-09 15:28:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
int n;
ll y;
int a[N],tot=0;
ll f[N],ans=100000000000000ll;
int q[N],nowl=1,nowr=0;
double Slope(int i,int j){
	ll x1=f[i]+(ll)a[i]*n-f[j]-(ll)a[j]*n;
	ll x2=a[i]-a[j];
	return (double)x1/x2;
}
int main(){
	scanf("%d %lld\n",&n,&y);
	int lst=0;
	for(int i=1;i<=n;i++){
		char x;
		scanf("%c",&x);
		//cout<<i<<" "<<x<<endl;
		if(x=='?') a[++tot]=(i-lst-1),lst=i;
	}
	for(int i=1;i<=tot;i++) a[i]+=a[i-1];
	for(int i=1;i<=tot;i++) f[0]+=a[i];
	ans=min(ans,f[0]);//for(int i=1;i<=tot;i++) cout<<a[i]<<" ";cout<<endl;
	q[++nowr]=0;
	for(int i=1;i<=tot;i++){
		while(nowl<nowr && Slope(q[nowl],q[nowl+1])<i) nowl++;
		int p=q[nowl];
		f[i]=f[p]+y-(ll)(a[i]-a[p])*(tot-i+1);ans=min(ans,f[i]);
		//cout<<i<<" zhuan: "<<p<<" "<<f[i]<<endl;
		while(nowl<nowr && Slope(q[nowr-1],q[nowr])>Slope(q[nowr],i)) nowr--;
		q[++nowr]=i;
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 7820kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

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

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

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

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 7724kb

input:

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

output:

6

result:

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