QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561637 | #5301. Modulo Ruins the Legend | qwqpmp | WA | 0ms | 3876kb | C++17 | 1.7kb | 2024-09-13 03:13:36 | 2024-09-13 03:13:36 |
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;
}
signed main(){
// freopen("qwq.in","r",stdin);
// freopen("qwq.out","w",stdout);
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<<(x*r+cnm*m)<<" "<<(y*r+cnm*m)<<endl;
} else {
cout<<d-sum<<endl;
r++;
cout<<(x*r+cnm*m)<<" "<<(y*r+cnm*m)<<endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3876kb
input:
6 24 1 1 4 5 1 4
output:
1 240003 239991
result:
wrong answer Integer parameter [name=s] equals to 240003, violates the range [0, 23]