QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727964 | #5301. Modulo Ruins the Legend | Fluoresce | WA | 0ms | 3584kb | C++20 | 1.6kb | 2024-11-09 14:16:28 | 2024-11-09 14:16:29 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define vec vector
#define pushk push_back
#define ump unordered_map
#define pl p<<1
#define pr p<<1|1
using namespace std;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9+7;
const ll inf = 1e18;
const ld eps = 1e-13;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy, _ = 1, __ = 1;
void bout(bool f) {
if (f)cout << "YES\n";
else cout << "NO\n";
}
ll n,m,k;
void exgcd(ll a,ll b,ll&x,ll&y){
if(!b){
x=a;
y=0;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
void ini() {
}
void solve() {
cin>>n>>m;
ll x,y,z,a,b,s,d,sum=0,r,x0,k,ans;
for(int i=1;i<=n;++i){
cin>>a;
sum+=a;
}
sum%=m;
if(n&1){
r=__gcd(n,m);
k=(m-sum+r-1)/r;
ans=(sum+k*r)%m;
exgcd(n,m,x0,y);
x=(x0*k%m+m)%m;
cout<<ans<<'\n'<<x<<' '<<0<<'\n';
}else{
r=__gcd(n/2,m);
k=(m-sum+r-1)/r;
ans=(sum+k*r)%m;
exgcd(n/2,m,x0,y);
x=(x0*k%m+m)%m;
if(x&1)d=1;
else d=0;
s=(x-(n+1)*d)/2;
s=(s%m+m)%m;
cout<<ans<<'\n'<<s<<' '<<d;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
streambuf *cinbp=cin.rdbuf(),*coutbp=cout.rdbuf();
ifstream fin("in.txt");
ofstream fout("out.txt");
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
#endif
//cin >> _;
__ = _;
ini();
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
6 24 1 1 4 5 1 4
output:
1 1 1
result:
wrong answer Result not equal to solution.