結果

問題 No.2488 Mod Sum Maximization
ユーザー silv723silv723
提出日時 2023-09-29 21:56:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,634 bytes
コンパイル時間 5,642 ms
コンパイル使用メモリ 293,500 KB
実行使用メモリ 6,036 KB
最終ジャッジ日時 2023-09-29 21:57:12
合計ジャッジ時間 51,371 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1,530 ms
5,816 KB
testcase_05 WA -
testcase_06 AC 1,590 ms
5,652 KB
testcase_07 WA -
testcase_08 AC 1,617 ms
5,692 KB
testcase_09 AC 1,374 ms
5,404 KB
testcase_10 WA -
testcase_11 AC 825 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,378 ms
4,956 KB
testcase_16 AC 868 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,524 ms
5,356 KB
testcase_20 AC 1,598 ms
5,596 KB
testcase_21 AC 1,494 ms
5,468 KB
testcase_22 AC 1,460 ms
5,680 KB
testcase_23 AC 1,480 ms
5,772 KB
testcase_24 WA -
testcase_25 AC 810 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 1,138 ms
4,716 KB
testcase_28 AC 1,179 ms
4,664 KB
testcase_29 AC 1,147 ms
4,716 KB
testcase_30 AC 1,032 ms
4,376 KB
testcase_31 AC 858 ms
4,380 KB
testcase_32 AC 1,377 ms
5,312 KB
testcase_33 AC 799 ms
4,380 KB
testcase_34 AC 1,489 ms
5,620 KB
testcase_35 AC 1,033 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 787 ms
4,376 KB
testcase_38 AC 805 ms
4,376 KB
testcase_39 AC 801 ms
4,380 KB
testcase_40 AC 787 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using i128 = __int128_t;
#define vs vector<string>
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define rep2(i,n) for(ll i=n-1;i>=0;i--)
#define rep3(i,a,b) for(ll i=a;i<=ll(b);i++)
#define rep4(i,a,b) for(ll i=a;i>=ll(b);i--)
#define forv(i,V) for(const auto& i:V)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SIZE(x) int(x.size())
constexpr ll mod=998244353;
//constexpr ll mod=1000000007;
#define pi 3.14159265358979323
#define INF32 2147483647
#define INF64 9223372036854775807
#define faster ios::sync_with_stdio(false);std::cin.tie(nullptr)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rev reverse
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define prq priority_queue
#define lb lower_bound
#define ub upper_bound
#define popcnt __builtin_popcountll
#define TLE while(true);
#define RE assert(false);
#define MLE vector<vector<vector<long long>>> mle_mle(400,vector<vector<long long>>(1000,vector<long long>(1000)));
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
#define rall(n) (n).rbegin(),(n).rend()
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
template<typename T,typename U>
ostream &operator<<(ostream&os,const pair<T,U>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T,typename U>
istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;}
template<typename T>
istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);}
template<class T>
void print(const T &t){cout<<t<<'\n';}
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);}
template<class... T>
void fin(const T &... a){print(a...);exit(0);}
ll max(int a,ll b){return max((ll)a,b);}
ll max(ll a,int b){return max((ll)b,a);}
ll min(int a,ll b){return min((ll)a,b);}
ll min(ll a,int b){return min((ll)b,a);}
//a以上b以下の個数
template<typename T>
ll RangeOK(ll a,ll b,vector<T> &v){
  return max(ub(all(v),b)-lb(all(v),a),0);
}
template <typename T>
vector<T> compress(vector<T> &X) {
    vector<T> vals = X;
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
int main(){
  LL(n);
  vll v(n);
  scan(v);
  ll ans = 0;
  ll sum = 0;
  rep(i, n){
    ans += v[i]%v[(i+1)%n];
    sum += v[i];
  }
  sum -= v[n-1];
  rep(i, n-1){
    ans = max(ans, sum-v[i]+v[n-1]%v[i]+v[i]%v[0]);
  }
  random_device seed_gen;
  mt19937 engine(seed_gen());
  if(v.size() > 4){
    rep(i, 100){
      ll cnt = 0;
      rep(j, n){
        cnt += v[j]%v[(j+1)%n];
      }
      shuffle(v.end()-4, v.end(), engine);
      ans = max(ans, cnt);
    }
  }
  if(v.size() < 15){
    rep(i, 100){
      ll cnt = 0;
      rep(j, n){
        cnt += v[j]%v[(j+1)%n];
      }
      shuffle(v.begin(), v.end(), engine);
      ans = max(ans, cnt);
    }
  }else{
    sort(all(v));
    ll cnt = 0;
    rep(i, n-10){
      cnt += v[i];
    }
    do{
      ll cnt2 = 0;
      rep(i, 10){
        cnt2 += v[n-i-1]%v[(n-i)%n];
      }
      ans = max(ans, cnt2+cnt);
    }while(next_permutation(v.end()-10, v.end()));
    sort(all(v));
    ll ct = 0;
    rep(i, n-10){
      cnt += v[n-2-i];
    }
    do{
      ll cnt2 = 0;
      rep(i, 10){
        cnt2 += v[(i+n-1)%n]%v[i];
      }
      ans = max(ans, cnt2+ct);
    }while(next_permutation(v.begin(),v.begin()+9));
  }
  fin(ans);
}
0