結果

問題 No.2519 Coins in Array
ユーザー 沙耶花
提出日時 2023-10-27 21:45:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 3,905 ms
コンパイル使用メモリ 258,292 KB
最終ジャッジ日時 2025-02-17 14:48:54
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]));
		if(X<=Y){
			cout<<X<<endl;
			cout<<2<<' '<<3<<endl;
			cout<<1<<' '<<2<<endl;
		}
		else{
			cout<<Y<<endl;
			cout<<1<<' '<<2<<endl;
			cout<<1<<' '<<2<<endl;
		}
	}
	if(n>=4){
		
		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;
}
0