結果
| 問題 |
No.2519 Coins in Array
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-27 23:21:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 324 ms / 2,000 ms |
| コード長 | 2,069 bytes |
| コンパイル時間 | 2,087 ms |
| コンパイル使用メモリ | 197,664 KB |
| 最終ジャッジ日時 | 2025-02-17 16:00:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<long long> A(N);
for(auto &a : A) cin >> a;
if(N == 2){
long long answer = (A.at(0)-1)*(A.at(1)-1);
if(A.at(0) <= 1 || A.at(1) <= 1) answer = 0;
if(gcd(A.at(0),A.at(1)) > 1) answer = 0;
cout << answer << endl;
cout << "1 2" << endl;
}
else if(N == 3){
long long a0 = A.at(0),a1 = A.at(1),a2 = A.at(2);
if(a0 <= 1 || a1 <= 1 || a2 <= 1){
cout << 0 << endl << "1 2" << endl << "1 2" << endl;
}
else if(a0%2 == 0 || a1%2 == 0 || a2%2 == 0){
cout << 0 << endl;
if(a0%2 == 0) cout << "2 3" << endl;
else if(a1%2 == 0) cout << "1 3" << endl;
else cout << "1 2" << endl;
cout << "1 2" << endl;
}
else{
long long answer = 8e18,left = -1;
for(int i=0; i<3; i++){
long long now = 1;
if(gcd(A.at(i),A.at((i+1)%3)) > 1){
answer = 0,left = (i+2)%3;
break;
}
now = (A.at(i)-1)*(A.at((i+1)%3)-1);
if(gcd(now,A.at((i+2)%3)) > 1){
answer = 0,left = (i+2)%3;
break;
}
now = (now-1)*(A.at((i+2)%3)-1);
if(now < answer) answer = now,left = (i+2)%3;
}
bool output = false;
cout << answer << endl;
for(int i=0; i<3; i++){
if(left == i) continue;
if(output) cout << " ";
output = true;
cout << i+1;
}
cout << endl << "1 2" << endl;
}
}
else{
cout << 0 << endl;
cout << "1 2" << endl << "1 2" << endl;
cout << N-3 << " " << N-2 << endl;
N -= 3;
while(N != 1){
cout << 1 << " " << N << endl;
N--;
}
}
}