提出 #33776745


ソースコード 拡げる

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
const int U=2e7;
vector<bool>prime(U+1,true);

ll solve(vector<pair<int,int>>odd, vector<pair<int,int>>even){
  int o=odd.size(),e=even.size();
  mf_graph<ll>g(o+e+2);//[0,o),[o,o+e),S=o+e,T=o+e+1
  int S=o+e,T=o+e+1;
  for(int i=0;i<o;i++)for(int j=0;j<e;j++){
    if(prime[odd[i].first+even[j].first])g.add_edge(i,o+j,1e9);
  }
  for(int i=0;i<o;i++)g.add_edge(S,i,odd[i].second);
  for(int i=0;i<e;i++)g.add_edge(o+i,T,even[i].second);
  return g.flow(S,T);
}

int main(){
  for(int i=2;i<=U;i++)if(prime[i])for(int j=i+i;j<=U;j+=i)prime[j]=false;
  
  vector<pair<int,int>>odd,even;
  int one_cnt=0;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    if(a==1)one_cnt=b;
    else if(a%2)odd.push_back({a,b});
    else even.push_back({a,b});
  }
  ll ret1=solve(odd,even);
  odd.push_back({1,one_cnt});
  ll ret2=solve(odd,even);
  cout << ret2 + (one_cnt-(ret2-ret1))/2 << endl;
}

提出情報

提出日時
問題 G - Erasing Prime Pairs
ユーザ kyopro_friends
言語 C++ (GCC 9.2.1)
得点 600
コード長 1063 Byte
結果 AC
実行時間 131 ms
メモリ 5340 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 50
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 02_has_one_small_01.txt, 02_has_one_small_02.txt, 02_has_one_small_03.txt, 02_has_one_small_04.txt, 02_has_one_small_05.txt, 02_has_one_small_06.txt, 02_has_one_small_07.txt, 02_has_one_small_08.txt, 02_has_one_small_09.txt, 02_has_one_small_10.txt, 03_has_one_large_01.txt, 03_has_one_large_02.txt, 03_has_one_large_03.txt, 03_has_one_large_04.txt, 03_has_one_large_05.txt, 03_has_one_large_06.txt, 03_has_one_large_07.txt, 03_has_one_large_08.txt, 03_has_one_large_09.txt, 03_has_one_large_10.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt, 04_handmade_10.txt, 05_handmade2_01.txt, 05_handmade2_02.txt, 05_handmade2_03.txt, 05_handmade2_04.txt, 06_handmade3_01.txt, 06_handmade3_02.txt, 06_handmade3_03.txt, 06_handmade3_04.txt, 07_handmade4_01.txt, 07_handmade4_02.txt, 07_handmade4_03.txt, 07_handmade4_04.txt, 07_handmade4_05.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 127 ms 5340 KiB
00_sample_02.txt AC 125 ms 5216 KiB
01_random_01.txt AC 123 ms 5256 KiB
01_random_02.txt AC 123 ms 5332 KiB
01_random_03.txt AC 124 ms 5260 KiB
01_random_04.txt AC 127 ms 5336 KiB
01_random_05.txt AC 124 ms 5332 KiB
02_has_one_small_01.txt AC 125 ms 5284 KiB
02_has_one_small_02.txt AC 124 ms 5224 KiB
02_has_one_small_03.txt AC 128 ms 5288 KiB
02_has_one_small_04.txt AC 124 ms 5332 KiB
02_has_one_small_05.txt AC 123 ms 5288 KiB
02_has_one_small_06.txt AC 124 ms 5260 KiB
02_has_one_small_07.txt AC 125 ms 5244 KiB
02_has_one_small_08.txt AC 124 ms 5328 KiB
02_has_one_small_09.txt AC 125 ms 5256 KiB
02_has_one_small_10.txt AC 125 ms 5256 KiB
03_has_one_large_01.txt AC 125 ms 5328 KiB
03_has_one_large_02.txt AC 129 ms 5328 KiB
03_has_one_large_03.txt AC 123 ms 5340 KiB
03_has_one_large_04.txt AC 124 ms 5328 KiB
03_has_one_large_05.txt AC 123 ms 5332 KiB
03_has_one_large_06.txt AC 125 ms 5324 KiB
03_has_one_large_07.txt AC 126 ms 5328 KiB
03_has_one_large_08.txt AC 124 ms 5260 KiB
03_has_one_large_09.txt AC 131 ms 5244 KiB
03_has_one_large_10.txt AC 127 ms 5224 KiB
04_handmade_01.txt AC 126 ms 5248 KiB
04_handmade_02.txt AC 125 ms 5248 KiB
04_handmade_03.txt AC 124 ms 5324 KiB
04_handmade_04.txt AC 127 ms 5192 KiB
04_handmade_05.txt AC 124 ms 5312 KiB
04_handmade_06.txt AC 125 ms 5312 KiB
04_handmade_07.txt AC 124 ms 5308 KiB
04_handmade_08.txt AC 127 ms 5244 KiB
04_handmade_09.txt AC 125 ms 5312 KiB
04_handmade_10.txt AC 127 ms 5260 KiB
05_handmade2_01.txt AC 125 ms 5252 KiB
05_handmade2_02.txt AC 129 ms 5324 KiB
05_handmade2_03.txt AC 127 ms 5316 KiB
05_handmade2_04.txt AC 123 ms 5220 KiB
06_handmade3_01.txt AC 124 ms 5252 KiB
06_handmade3_02.txt AC 125 ms 5252 KiB
06_handmade3_03.txt AC 124 ms 5252 KiB
06_handmade3_04.txt AC 125 ms 5328 KiB
07_handmade4_01.txt AC 125 ms 5252 KiB
07_handmade4_02.txt AC 127 ms 5244 KiB
07_handmade4_03.txt AC 124 ms 5324 KiB
07_handmade4_04.txt AC 125 ms 5312 KiB
07_handmade4_05.txt AC 123 ms 5316 KiB