結果

問題 No.1330 Multiply or Divide
ユーザー penguinman
提出日時 2020-09-12 03:54:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 173,560 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-21 22:54:35
合計ジャッジ時間 7,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 15 RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
int main(){
    int N,M; cin>>N>>M;
    const int max=1e5,inf=1e9;
    assert(1<=N&&N<=max&&1<=M&&M<=max);
    vector<int> A(N);
    int ans=0,sum=0;
    std::set<int> set;
    set.insert(M);
    for(int i=0;i<N;i++){
        cin>>A[i];
        assert(1<=A[i]&&A[i]<=inf);
        sum+=A[i]%M;
        sum%=M;
        ans=std::max(ans,sum+M-*set.upper_bound(sum));
        set.insert(sum);
    }
    if(N>1000){
        cout<<std::min(sum,M-1)<<endl;
        return 0;
    }
    cout<<ans<<endl;
}
0