結果

問題 No.2519 Coins in Array
ユーザー Nzt3Nzt3
提出日時 2023-10-27 22:25:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,830 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 216,104 KB
実行使用メモリ 5,924 KB
最終ジャッジ日時 2023-10-27 22:25:38
合計ジャッジ時間 7,551 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

pair<int,vector<array<int,2>>>dfs(vector<ll> v){
  assert(!v.empty());
  if(v.size()==1){
    return make_pair(v[0],vector<array<int,2>>());
  }
  int N=v.size();
  vector<array<int,2>>ret;
  ll m=1e18;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      vector v2(0,0ll);
      for(int k=0;k<N;k++){
        if(k!=i&&k!=j)v2.push_back(v[k]);
      }
      if(gcd(v[i],v[j])!=1)v2.push_back(0);
      else v2.push_back(v[i]*v[j]-v[i]-v[j]+1);
      auto [n,rv]=dfs(v2);
      if(n<m){
        m=n;
        rv.push_back({i+1,j+1});
        ret=rv;
      }
    }
  }
  return make_pair(m,ret);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector A(N,0ll);
  int idx1=-1;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]==1){
      idx1=i;
    }
  }
  if(idx1==-1){
    if(N<4){
      auto [m,v]=dfs(A);
      cout<<m<<'\n';
      for(auto i:v)cout<<i[0]<<' '<<i[1];
    }else{
      cout<<"0\n";
      vector odd(0,0),even(0,0);
      for(int i=0;i<N;i++){
        if(A[i]%2){
          odd.push_back(i);
        }else{
          even.push_back(i);
        }
      }
      while(even.size()<2){
        int k1=odd.back();
        odd.pop_back();
        int k2=odd.back();
        odd.pop_back();
        for(int &i:even){
          if(i>k1)i-=1;
        }
        for(int &i:even){
          if(i>k2)i-=1;
        }
        even.push_back(odd.size()+even.size());
        cout<<k1+1<<' '<<k2+1<<'\n';
      }
      cout<<even[0]+1<<' '<<even[1]+1<<'\n';
      for(int i=odd.size()+even.size()-1;i>1;i--){
        cout<<i<<" 1\n";
      }
    }
  }else{
    cout<<"0\n";
    if(idx1==0){
      cout<<"1 2\n";
    }else{
      cout<<idx1+1<<" 1\n";
    }
    for(int i=N-1;i>1;i--){
      cout<<i<<" 1\n";
    }
  }
}
0