結果

問題 No.2519 Coins in Array
ユーザー 沙耶花沙耶花
提出日時 2023-10-27 21:49:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,520 bytes
コンパイル時間 4,270 ms
コンパイル使用メモリ 264,580 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-10-27 21:49:37
合計ジャッジ時間 12,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 RE -
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 2 ms
4,348 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
権限があれば一括ダウンロードができます

ソースコード

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){
		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;
}
0