QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561644#5301. Modulo Ruins the LegendqwqpmpWA 7ms4644kbC++171.7kb2024-09-13 03:31:092024-09-13 03:31:10

Judging History

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

  • [2024-09-13 03:31:10]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:4644kb
  • [2024-09-13 03:31:09]
  • 提交

answer

// 日丽风和, 希望大家可以平安归来;
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("inline")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n'
#define ayy(x) array<int,x>
#define ys(x) (x?"Yes":"No")
#define SZ(x) ((int)(x).size())
#define int long long
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand()%x; }
const ll mod=1000000007,off=5;
const int MAXN=2e5+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// head

ll a[MAXN];
ll n,m;

ll exgcd(ll a,ll b,ll &x,ll &y){
	if (b==0) {
		x=1;
		y=0; 
		return a;
	}
	ll d=exgcd(b,a%b,x,y);
	ll z=x;
	x=y;
	y=z-y*(a/b);
	return d;
}

ll fix(ll x,ll m) {
	return (x%m+m)%m;
}

signed main(){
	scanf("%lld%lld",&n,&m);
	ll sum=0;
	rep(i,1,n+1) {
		scanf("%lld",&a[i]);
		sum=(sum+a[i])%m;
	}
	sum=sum%m;
	if (!sum) {
		cout<<0<<endl;
		cout<<0<<" "<<0<<endl;
	} else {
		ll x=0,y=0,d=exgcd(n,(n+1)*n/2,x,y);
		ll r=(m-sum)/d;
		sum=(m-sum)%d;
		if (sum<=d-sum) {
			cout<<sum<<endl;
			cout<<fix(x*r,m)<<" "<<fix(y*r,m)<<endl;
		} else {
			cout<<d-sum<<endl;
			r++;
			// cerr<<x*r<<" "<<y*r<<endl;
			cout<<fix(x*r,m)<<" "<<fix(y*r,m)<<endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
15 3

result:

ok ok

Test #2:

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

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

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

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

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

input:

1 1000000000
963837005

output:

0
0 36162995

result:

ok ok

Test #5:

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

input:

2 1
0 0

output:

0
0 0

result:

ok ok

Test #6:

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

input:

2 1000000000
948507269 461613424

output:

0
410120693 589879307

result:

ok ok

Test #7:

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

input:

100000 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
0 0

result:

ok ok

Test #8:

score: -100
Wrong Answer
time: 7ms
memory: 4644kb

input:

100000 1000000000
253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...

output:

3387
536000000 9280

result:

wrong answer Result not equal to solution.