QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#35672#975. GameFroggyguaWA 40ms10628kbC++171.1kb2022-06-17 21:53:222022-06-17 21:53:23

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-17 21:53:23]
  • Judged
  • Verdict: WA
  • Time: 40ms
  • Memory: 10628kb
  • [2022-06-17 21:53:22]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define N 500050
typedef long long ll;
const int mod=998244353;
int n,inv[N];
ll a[N];
struct Point{
	ll x,y;
	Point(ll _x=0,ll _y=0):x(_x),y(_y){}
	friend Point operator - (const Point &a,const Point &b){
		return Point(a.x-b.x,a.y-b.y);
	}
	friend ll operator % (const Point &a,const Point &b){
		return a.x*b.y-a.y*b.x;
	}
};
inline bool Left(Point a,Point b){
	return b%a>0;
}
void init(int n){
	inv[1]=1;
	for(int i=2;i<=n;++i){
		inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	init(n);
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	static int st[N],top;
	for(int i=1;i<=n;++i){
		while(top>1&&!Left(Point(st[top],a[st[top]])-Point(st[top-1],a[st[top-1]]),Point(i,a[i])-Point(st[top-1],a[st[top-1]])))--top;
		st[++top]=i;
	}
	int ans=a[n];
	for(int k=1;k<top;++k){
		for(int i=st[k];i<st[k+1];++i){
			ans=(ans+a[st[k]]+1LL*(a[st[k+1]]-a[st[k]])%mod*(i-st[k])%mod*inv[st[k+1]-st[k]])%mod;
		}
	}
	ans=(ans+mod)%mod;
	cout<<1LL*ans*inv[n]%mod<<'\n';
	return 0;
}



详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7660kb

input:

3
3 1 2

output:

499122179

result:

ok "499122179"

Test #2:

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

input:

6
6 1 2 5 3 4

output:

582309211

result:

ok "582309211"

Test #3:

score: -100
Wrong Answer
time: 40ms
memory: 10628kb

input:

500000
131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...

output:

764743519

result:

wrong answer 1st words differ - expected: '131032905', found: '764743519'