QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666799#5301. Modulo Ruins the LegendvcoistntTL 104ms3728kbC++171.9kb2024-10-22 19:59:272024-10-22 19:59:36

Judging History

This is the latest submission verdict.

  • [2024-10-22 19:59:36]
  • Judged
  • Verdict: TL
  • Time: 104ms
  • Memory: 3728kb
  • [2024-10-22 19:59:27]
  • Submitted

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

output:


result: