QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666799 | #5301. Modulo Ruins the Legend | vcoistnt | TL | 104ms | 3728kb | C++17 | 1.9kb | 2024-10-22 19:59:27 | 2024-10-22 19:59:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define lowbit(x) ((x)&-(x))
typedef pair<int,int> pll;
const int N=2e5+10;
const int INF=0x3f3f3f3f3f3f3f3f;
const int inf=INT_MIN;
const int mod=998244353;
const int base=283;
void solve(){
int n,m;
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++){
int x;cin>>x;
sum+=x;
}
int a=n,b=(n+1)*n/2;
sum%=m;
if(n%2){
int mi=INF;
int x=-1;
for(int i=0;i<m;i++){
int t=(sum+i*a)%m;
if(t<mi){
mi=t;
x=i;
}
if(mi==0) break;
}
cout<<mi<<"\n";
cout<<x<<" "<<0<<"\n";
}else{
int flag=1;
int t=n/2;
int mi=INF;
int x=-1;
for(int i=0;i<m;i++){
if(i>t){
int y=(sum+i*n)%m;
int yy=(sum+i*n+n/2)%m;
if(y<mi){
flag=1;
mi=y;
x=i;
}
if(yy<mi){
mi=yy;
x=i;
flag=0;
}
if(mi==0){break;}
}else{
int y=(sum+i*n)%m;
if(y<mi){
flag=1;
mi=y;
x=i;
}
if(mi==0) break;
}
}
if(flag==0){
cout<<mi<<"\n";
cout<<x-t<<" "<<1<<"\n";
}else{
cout<<mi<<'\n';
cout<<x<<" "<<0<<"\n";
}
}
}
signed main() {
vcoistnt
int _=1;
// cin>>_;
while(_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
6 24 1 1 4 5 1 4
output:
1 2 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
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: 3652kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 104ms
memory: 3588kb
input:
1 1000000000 963837005
output:
0 36162995 0
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: -100
Time Limit Exceeded
input:
2 1000000000 948507269 461613424