結果
問題 | No.2519 Coins in Array |
ユーザー |
![]() |
提出日時 | 2023-10-27 21:50:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 353 ms / 2,000 ms |
コード長 | 1,661 bytes |
コンパイル時間 | 4,380 ms |
コンパイル使用メモリ | 258,308 KB |
最終ジャッジ日時 | 2025-02-17 14:53:29 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 long long get(long long a,long long b){ if(gcd(a,b)!=1)return 0; return (a-1)*(b-1); } int main(){ int n; cin>>n; deque<long long> a(n); rep(i,n){ cin>>a[i]; } if(n==2){ cout<<get(a[0],a[1])<<endl; cout<<1<<' '<<2<<endl; return 0; } if(n==3){ long long X = get(a[0],get(a[1],a[2])); long long Y = get(a[2],get(a[0],a[1])); long long Z = get(a[1],get(a[0],a[2])); if(X<=Y&&X<=Z){ cout<<X<<endl; cout<<2<<' '<<3<<endl; cout<<1<<' '<<2<<endl; } else if(Y<=Z){ cout<<Y<<endl; cout<<1<<' '<<2<<endl; cout<<1<<' '<<2<<endl; } else{ cout<<Z<<endl; cout<<1<<' '<<3<<endl; cout<<1<<' '<<2<<endl; } } if(n>=4){ //assert(false); cout<<0<<endl; deque<long long> F; while(a.size()>=2){ long long A = a.front(); a.pop_front(); long long B = a.front(); a.pop_front(); if(A%2==1&&B%2==1){ cout<<F.size()+1<<' '<<F.size()+2<<endl; a.push_back(get(A,B)); } else{ F.push_back(A); F.push_back(B); } } while(F.size()>0){ a.push_front(F.back()); F.pop_back(); } rep(i,a.size()){ if(a[i]%2==1)continue; for(int j=i+1;j<a.size();j++){ if(a[j]%2==1)continue; cout<<i+1<<' '<<j+1<<endl; a.erase(a.begin()+j); a.erase(a.begin()+i); a.push_back(0); while(a.size()>=2){ cout<<1<<' '<<a.size()<<endl; a.pop_back(); } return 0; } } } return 0; }