QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561639 | #5301. Modulo Ruins the Legend | qwqpmp | WA | 0ms | 3788kb | C++17 | 1.7kb | 2024-09-13 03:21:16 | 2024-09-13 03:21:16 |
Judging History
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())
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
const int cnm=10000;
ll a[MAXN];
ll n,m;
ll exgcd(ll a,ll b,ll &x,ll &y) {
if (!b) {
x=1,y=0;
return a;
}
ll d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
ll fix(ll x,ll m) {
if (x>=0) return x;
else {
ll y=ceil((db)(-x)/m);
return (x+m*y);
}
}
signed main(){
scanf("%lld%lld",&n,&m);
ll sum=0;
rep(i,1,n+1) {
scanf("%lld",&a[i]);
sum+=a[i];
}
sum=sum%m;
if (!sum) {
cout<<0<<endl;
cout<<0<<" "<<0<<endl;
} else {
ll x=0,y=0,d=exgcd(n*(n+1)/2,n,x,y);
// cerr<<"a:"<<n*(n+1)/2<<" b:"<<n<<endl;
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: 0
Wrong Answer
time: 0ms
memory: 3788kb
input:
6 24 1 1 4 5 1 4
output:
1 3 15
result:
wrong answer Result not equal to solution.