結果
問題 | No.2519 Coins in Array |
ユーザー | 👑 binap |
提出日時 | 2023-10-27 22:42:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,528 bytes |
コンパイル時間 | 4,281 ms |
コンパイル使用メモリ | 265,260 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-25 14:42:52 |
合計ジャッジ時間 | 8,751 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 98 ms
6,940 KB |
testcase_24 | AC | 93 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 95 ms
6,940 KB |
testcase_28 | AC | 96 ms
6,944 KB |
testcase_29 | AC | 95 ms
6,940 KB |
testcase_30 | AC | 84 ms
6,944 KB |
testcase_31 | AC | 16 ms
6,944 KB |
testcase_32 | AC | 46 ms
6,940 KB |
testcase_33 | AC | 65 ms
6,948 KB |
testcase_34 | AC | 32 ms
6,944 KB |
testcase_35 | AC | 60 ms
6,940 KB |
testcase_36 | AC | 25 ms
6,940 KB |
testcase_37 | AC | 12 ms
6,940 KB |
testcase_38 | AC | 49 ms
6,944 KB |
testcase_39 | AC | 29 ms
6,944 KB |
testcase_40 | AC | 67 ms
6,944 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; template <int m> std::ostream& operator<<(std::ostream& os, const atcoder::static_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} int main(){ int n; cin >> n; vl a(n); cin >> a; auto func = [&](ll x, ll y){ if(x == 0 or y == 0) return (long long)0; ll g = gcd(x, y); if(g >= 2) return (long long)0; else return (x - 1) * (y - 1); }; if(n >= 4){ vi e; vi o; rep(i, n){ if(a[i] % 2 == 0){ e.push_back(i); if(int(e.size()) >= 2 and int(o.size()) >= 4) break; }else{ o.push_back(i); if(int(e.size()) >= 2 and int(o.size()) >= 4) break; } } cout << "0\n"; if(int(e.size()) >= 2){ cout << e[0] + 1 << ' ' << e[1] + 1 << "\n"; rep(i, n - 2){ cout << 1 << ' ' << n - 1 - i << "\n"; } return 0; } if(int(e.size()) == 1){ cout << o[0] + 1 << ' ' << o[1] + 1 << "\n"; int cnt = 0; if(o[0] < e[0]) cnt++; if(o[1] < e[0]) cnt++; e[0] -= cnt; cout << e[0] + 1 << ' ' << n - 1 << "\n"; rep(i, n - 3){ cout << 1 << ' ' << n - 2 - i << "\n"; } return 0; } cout << o[0] + 1 << ' ' << o[1] + 1 << "\n"; o[2] -= 2; o[3] -= 2; cout << o[2] + 1 << ' ' << o[3] + 1 << "\n"; cout << n - 3 << ' ' << n - 2 << "\n"; rep(i, n - 4){ cout << 1 << ' ' << n - 3 - i << "\n"; } return 0; } vi perm(n); rep(i, n) perm[i] = i; vi ans_perm = perm; ll ans = 1001001001001001001; do{ long long tmp = 0; if(n == 2) tmp = func(a[perm[0]], a[perm[1]]); if(n == 3) tmp = func(func(a[perm[0]], a[perm[1]]), a[perm[2]]); if(tmp < ans){ ans = tmp; ans_perm = perm; } }while(next_permutation(perm.begin(), perm.end())); cout << ans << "\n"; cout << ans_perm[0] + 1 << ' ' << ans_perm[1] + 1 << "\n"; if(n == 3) cout << "1 2\n"; return 0; }