QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#437850 | #5554. Breeding Bugs | tz3528 | WA | 95ms | 44804kb | C++20 | 1.9kb | 2024-06-09 18:49:46 | 2024-06-09 18:49:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=2e7+10;
bool vis[maxn];
ll prime[maxn/10], p_sz, z;
void get_number() {
for(int i=2;i<maxn;i++){
if (!vis[i]) {
prime[p_sz++] = i;
}
for(ll j=0;j<p_sz&&(z=i*prime[j])<maxn;++j) {
vis[z] = 1;
if (i % prime[j] == 0) break;
}
}
}
const int p_max=810,q_max=1000010;
int n,m,s,t,edge=1;
int d[p_max],now[p_max],to[q_max],Next[q_max],fir[q_max];
int v[q_max],ans=0;
void add(int x,int y,int w){
to[++edge]=y; v[edge]=w; Next[edge]=fir[x]; fir[x]=edge;
to[++edge]=x; v[edge]=0; Next[edge]=fir[y]; fir[y]=edge;
}
bool bfs(){
memset(d,0, sizeof(d));
queue<int> q;
q.push(s);
d[s]=1;
now[s]=fir[s];
while(!q.empty()){
int x=q.front();q.pop();
for(int i=fir[x];i;i=Next[i]){
if(!d[to[i]]&&v[i]){//为分层且有权值的边才进行遍历
q.push(to[i]);
now[to[i]]=fir[to[i]];
d[to[i]]=d[x]+1;
if(to[i]==t) return true;
}
}
}
return false;
}
int dfs(int u, int flow){
if(u==t) return flow;
int rest=flow,k,i;
for(i=now[u];i&&rest;i=Next[i]){
if(v[i]&&d[to[i]]==d[u]+1){
k=dfs(to[i],min(rest,v[i]));//找最小流
if(!k) d[to[i]]=0;//剪枝,删掉已经增广过的点
v[i]-=k;
v[i^1]+=k;
rest-=k;//从u出发的点要消耗k
}
}
now[u]=i;//将u的下一个结点置空,避免重复
return flow-rest;//返回在u点的最大流出
}
int dinic(){
ans=0;
while(bfs()) ans+=dfs(s,1e8);
return ans;
}
int main(){
get_number();
cin>>n;
vector<int> p(n+1);
int flag=1,cnt=0;
for(int i=1;i<=n;i++){
int x;cin>>x;
if(x==1){
if(flag==0) continue;
flag=0;
}
p[++cnt]=x;
}
n=cnt,s=0,t=n+1;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!vis[p[i]+p[j]])add(i,j,1);
for(int i=1;i<=n;i++){
if(p[i]%2) add(s,i,1);
else add(i,t,1);
}
cout<<n-dinic()<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 81ms
memory: 38556kb
input:
8 1 2 3 4 5 6 7 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 76ms
memory: 38032kb
input:
5 7 13 2 2 4
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 76ms
memory: 37352kb
input:
2 1 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 79ms
memory: 38888kb
input:
3 1 2 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 84ms
memory: 38240kb
input:
749 636 51 149 35 143 172 595 226 743 512 547 310 622 304 729 540 110 241 169 201 690 167 47 493 689 162 491 104 354 592 44 358 331 301 373 716 351 630 389 253 224 292 671 440 192 613 150 588 485 549 624 75 282 535 695 426 78 640 408 119 203 580 309 587 357 707 115 720 606 565 434 590 741 133 420 51...
output:
375
result:
ok single line: '375'
Test #6:
score: 0
Accepted
time: 81ms
memory: 42716kb
input:
749 1815 1771 2013 1986 1919 1845 2073 1740 1583 1586 1834 1928 1861 1475 1366 1472 1382 1600 1621 1653 1424 1623 1556 1524 1817 1850 1770 1427 1358 1979 1420 1449 1852 1365 1806 1455 1810 1947 1726 1819 2072 1898 1557 2071 2026 1481 1359 1523 1643 2033 1510 1573 1935 1622 1350 1487 1743 1559 1641 1...
output:
375
result:
ok single line: '375'
Test #7:
score: 0
Accepted
time: 70ms
memory: 39040kb
input:
749 9999669 9999743 9999352 9999704 9999476 9999703 9999438 9999803 9999984 9999633 9999569 9999608 9999275 9999350 9999967 9999873 9999761 9999300 9999764 9999474 9999962 9999288 9999472 9999573 9999480 9999315 9999720 9999757 9999671 9999835 9999700 9999758 9999426 9999755 9999766 9999904 9999957 ...
output:
375
result:
ok single line: '375'
Test #8:
score: 0
Accepted
time: 75ms
memory: 37988kb
input:
749 5939005 140 116 4682136 1761602 154 228 158570 7679414 3670019 17 145 185 9406644 141 9287622 9987191 195 165 7738619 93 8893114 130 9154550 777182 1567373 6572984 2491452 3621298 234 6 138 8537635 83 1229997 1480689 3145258 201471 138 250 8844984 27 1605725 6171522 8026356 131 9987869 191 13 30...
output:
378
result:
ok single line: '378'
Test #9:
score: 0
Accepted
time: 83ms
memory: 40184kb
input:
749 2332958 6180895 7905522 235 115 244 161 9034571 1362164 623051 612462 2571102 42 128 10 111 2956605 9373811 8469417 39 36 96 7530501 40 4790237 2793893 7453444 3762528 7430632 1745194 8733280 9592746 91 9 115 211 1948966 3882472 169 8398684 4034077 175 49 842557 8404493 101 4379660 3376505 44248...
output:
374
result:
ok single line: '374'
Test #10:
score: 0
Accepted
time: 76ms
memory: 40364kb
input:
749 134 5500115 6816197 177 113 39 118 24 95 104 127846 1350242 136 4 142 2941199 6401410 86 454850 244 8902332 115 666972 5265264 166 9291560 32 1678385 1076606 9074495 1505045 46 246 172832 70 8414011 9842934 5110562 2429042 108 3267283 118 8782469 78 8163037 9693554 194 4 245 4168276 7701806 6876...
output:
387
result:
ok single line: '387'
Test #11:
score: 0
Accepted
time: 86ms
memory: 40560kb
input:
749 142 3157863 176 7385582 18 136 93 996229 5259293 16 3251236 173 2213931 2363274 33 3356459 161 1125309 5986003 25 4 188 5858614 100 5634872 2722753 253 4451160 3225247 159 213 203 227 162 2473119 154 125 56 4688436 159 5278056 8605375 9945750 49 8659797 162 90 218 5970119 66 10649 33 4151196 46 ...
output:
385
result:
ok single line: '385'
Test #12:
score: 0
Accepted
time: 84ms
memory: 42724kb
input:
749 2712081 71 236 143 3211032 9722089 180 203 4533157 178 225 26976 7749575 1262900 643082 4795550 5672222 8012648 102 2645098 3694416 6086260 4398225 5703990 4274780 6874662 83 101 203 136 65 231 4038831 6748776 165 9691431 55 81419 3683567 3296282 7416791 1036452 83 121 2453752 4972444 9674832 14...
output:
378
result:
ok single line: '378'
Test #13:
score: 0
Accepted
time: 83ms
memory: 40168kb
input:
749 8339940 9296039 137 9317307 221 2128061 54 6 23 7179362 46 130 8737515 6724928 4941224 216 118 7397608 140 162 856319 9131313 151 6447330 54 145 8765664 244 5669004 3498881 210 132 7563480 176 2467428 678196 152 216 2841428 739831 9816377 2973634 9838285 223 8800877 233 4484218 5627771 4395985 1...
output:
384
result:
ok single line: '384'
Test #14:
score: 0
Accepted
time: 84ms
memory: 42556kb
input:
749 149 124 3605219 1420789 33 7843555 170 186 4291835 8077969 2614124 165 106 521324 35 9 15 7438705 7709424 5610921 12 186 117 7578827 254 5689552 101 8575532 3817548 19 1243187 40 2326755 145 141 251 84 48 169 110 40 1905983 9366846 929982 6026857 122 6633524 968001 103 202 8343291 227 1944018 22...
output:
379
result:
ok single line: '379'
Test #15:
score: 0
Accepted
time: 84ms
memory: 39308kb
input:
749 100 8287048 45 4197216 26 1950491 98 4304791 245 184 142 2712028 134995 45 123 18 2656141 8805691 28 120 8297367 5882622 216 56 123 85 239 802637 3584661 3641679 220 230 3864526 9175642 113 4926485 8779305 1498095 5025013 66 31 126 66 4065967 162 4188980 3530125 167 142 6841207 1618728 1710360 6...
output:
376
result:
ok single line: '376'
Test #16:
score: 0
Accepted
time: 84ms
memory: 37696kb
input:
749 3912636 802328 6855875 244 7342189 209 3250851 4050800 73 779981 2509585 7580357 76 5721513 9738941 9878939 6122795 6732681 239 565510 6098832 495615 152 56 6126945 543165 131 117 4670324 4488986 138 3519388 218 101 17698 118 1380490 184 95 218 195 3414098 7990084 253 166 5527193 2246323 8250955...
output:
402
result:
ok single line: '402'
Test #17:
score: 0
Accepted
time: 84ms
memory: 40476kb
input:
749 8682473 3384807 8359398 95 9101649 8272198 24 178 100 138 194 86 24 7563420 2090794 161 245889 6465662 9354963 200 229 251 8445960 251 6747505 163281 8791794 7309904 5313071 3888038 186 130 5550908 9744515 5518855 206 4434937 3810863 151 5 253 4889695 244 173 6734404 2865039 77 5373531 2230077 6...
output:
376
result:
ok single line: '376'
Test #18:
score: 0
Accepted
time: 83ms
memory: 39156kb
input:
749 145 255 2511242 210 31 130 252 3256468 107 125 1061011 2565811 8724242 122 4273255 8617164 216 2535664 3139976 14 3081472 44 330526 1820598 70 210 5627971 31 116 8216077 2686919 209 6355398 15 4432645 1280401 3018645 9509416 222 5749004 3987238 5711665 249 2152389 9531460 70 2250180 52 153 92572...
output:
378
result:
ok single line: '378'
Test #19:
score: 0
Accepted
time: 73ms
memory: 40864kb
input:
749 186 30 8025614 9733608 95 35 3879624 141 3083486 2478248 100 493791 3364932 81 8269147 193 79 187848 9457098 9125572 7747079 192 4529365 32 5266146 113 4730363 7596358 9354008 60 2407988 222 4 136 8546916 138 226 658725 3939610 110 281204 6893629 228 223 4318669 3590988 3522406 59 5054612 299843...
output:
379
result:
ok single line: '379'
Test #20:
score: 0
Accepted
time: 82ms
memory: 39744kb
input:
749 250 2151714 3525079 157 68 33 126 15 9034268 7223315 7163195 6939192 2987411 39 2945590 7540421 8072687 210 9437680 7410254 100 205 210 5467325 51 7987980 126 231 4411190 5240608 164 3529829 7623941 5522379 110 40 6558055 3496921 173 245 1268345 1246377 5814442 253 252 1817302 1343448 166 472086...
output:
389
result:
ok single line: '389'
Test #21:
score: 0
Accepted
time: 81ms
memory: 42680kb
input:
749 166 106 228 8037675 126 148 26 79 105 2365998 59 115 6566394 197 173 156 2201741 9166937 218 2439759 18 158 4367175 4576683 168 180 185 5617949 5350059 5 81 28 7325306 19 4224943 9697848 224 2207235 134 158 55578 123 2982034 188 152 8640550 1195621 170 4473548 36 9206138 5436165 8414383 5328135 ...
output:
374
result:
ok single line: '374'
Test #22:
score: 0
Accepted
time: 80ms
memory: 42428kb
input:
749 206 2298800 8273789 210 5020800 8003138 1717932 418281 37 79 153 112660 1726363 11 7171359 52 37 3070655 6034023 1895717 6664792 4401253 117 178 206 2626427 8 199 765962 8286478 8230927 4072807 53 3669476 53 15 5854917 229 1122528 41 121 162 58 171459 18 115 221 49 3212942 5794045 1144622 111 98...
output:
389
result:
ok single line: '389'
Test #23:
score: 0
Accepted
time: 80ms
memory: 38824kb
input:
749 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 2 1 1 2 1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 2 1 2 2 1 1 1 1 1 2 2 1 2 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 2 2 1 2 1 2 2 2 2 1 1 2 1 2 1 1 1 1 1 1 1 2 2 2 2 2 1 2 1 1 2 1 2 2 2 2 1 1 1 1 1 2 1 1 1 2 1 2 1 2 2 2 1 2 2 2 2 1 2 ...
output:
374
result:
ok single line: '374'
Test #24:
score: 0
Accepted
time: 84ms
memory: 44244kb
input:
749 2 3 5 2 5 3 3 2 2 2 3 5 3 3 5 5 3 2 2 3 5 3 5 5 3 2 2 5 5 3 2 2 3 2 5 5 3 2 2 3 2 3 3 5 2 5 2 2 3 3 3 5 3 2 2 2 3 5 3 2 2 2 5 2 2 5 5 5 3 5 2 2 5 5 3 3 3 5 3 3 2 3 3 3 5 2 3 5 5 2 3 2 5 3 3 5 3 3 3 5 2 3 3 2 2 5 3 3 5 5 2 3 5 2 2 2 2 3 3 5 5 2 5 2 3 2 3 2 2 2 3 5 3 3 5 3 3 2 5 5 2 2 2 3 5 2 3 3 ...
output:
491
result:
ok single line: '491'
Test #25:
score: 0
Accepted
time: 78ms
memory: 44316kb
input:
749 2 5 5 3 2 3 5 5 2 5 2 2 5 2 2 3 2 5 3 3 2 2 2 5 2 5 2 3 2 3 2 5 2 3 3 5 3 5 3 3 5 2 3 2 2 5 2 2 2 2 2 2 2 2 2 2 2 3 5 2 2 3 2 2 3 2 5 5 2 2 2 5 5 5 2 2 2 5 3 5 2 5 2 2 5 2 2 2 2 3 2 3 2 2 5 2 3 3 2 2 5 3 3 3 3 5 2 5 2 2 3 5 2 2 3 2 2 2 5 3 5 5 2 2 2 2 3 2 3 3 3 2 2 2 2 2 5 3 5 2 2 3 5 2 3 2 3 3 ...
output:
383
result:
ok single line: '383'
Test #26:
score: 0
Accepted
time: 95ms
memory: 44492kb
input:
749 8817 30847 29857 15367 64 21190 26872 3142 5329 37402 622 21820 1810 8839 9682 7009 8209 12619 16807 33982 1264 2737 31144 3127 2584 9514 19480 2277 22450 24577 23737 177 10357 39010 2959 27304 7677 21592 33172 36757 11127 15087 637 3217 49162 10687 1887 9289 11554 919 6027 229 7930 24280 23764 ...
output:
376
result:
ok single line: '376'
Test #27:
score: 0
Accepted
time: 88ms
memory: 40828kb
input:
749 5951 46148 662 38261 6509 5618 47105 10728 3011 23558 24152 7475 22502 10152 1908 6299 3992 14648 612 32 26462 16709 15875 4328 18755 24059 33095 25115 28368 7079 13262 14262 38711 15359 4742 38798 10922 3152 7542 6792 2018 27848 11958 28811 31691 3131 15749 5621 26165 2432 5909 13232 38672 1686...
output:
375
result:
ok single line: '375'
Test #28:
score: 0
Accepted
time: 86ms
memory: 40208kb
input:
749 40082 431 31898 25385 7661 24872 261 6605 11975 1772 26471 11516 8786 5606 48725 1545 16688 5115 5331 15128 35966 2061 46811 41585 9341 7221 38495 29246 15632 9741 285 12645 19575 5522 4178 24422 5312 25625 13586 191 38231 31976 45548 37892 8411 8915 10892 27605 14625 15842 38981 8918 891 3225 4...
output:
375
result:
ok single line: '375'
Test #29:
score: 0
Accepted
time: 83ms
memory: 40180kb
input:
749 665072 4348295 425867 5297702 1817022 5293379 6064037 1112882 5939054 7550822 597347 8629187 7972862 3895649 505584 2177975 1920494 6934302 7169927 7096607 4227605 1625492 4859537 4870812 6478145 419654 1845377 3730535 461519 3773267 1171902 7915574 491219 1047407 3549569 5302574 1179074 1611962...
output:
375
result:
ok single line: '375'
Test #30:
score: 0
Accepted
time: 83ms
memory: 42944kb
input:
749 5437390 111300 1634629 317490 2926549 328159 2929792 5910241 3623980 905910 3056119 1935499 236110 4407828 59650 4282008 2940448 3006799 792232 9055369 5506051 1947961 4672528 651472 5486101 5232799 6615738 5004121 94792 277590 5553229 1902852 2621052 1363699 4274161 1632499 1348018 835351 65018...
output:
375
result:
ok single line: '375'
Test #31:
score: 0
Accepted
time: 86ms
memory: 38028kb
input:
749 2431145 6459776 1691646 1227461 4924446 896843 1454723 7693283 3042575 1013723 632891 2451818 3461246 2292488 1216298 3770408 454698 7233503 6766025 5069888 6396173 8816816 2800316 4990811 1294391 8336783 5681543 1653126 751976 8187371 3008636 4485533 6060155 1621668 2190605 7390085 2470028 1600...
output:
375
result:
ok single line: '375'
Test #32:
score: 0
Accepted
time: 82ms
memory: 37940kb
input:
499 6106404 4182908 180377 5124722 6665789 7267164 6232975 7280886 4337586 1154399 8065214 538673 9213224 4931018 8159290 2505624 1736190 1873001 3219119 1360768 6764800 7392585 1045973 2424623 5584252 3284074 3592680 9768207 4556048 4175526 8183955 4328184 3394108 4300749 8734130 2270922 1371042 29...
output:
356
result:
ok single line: '356'
Test #33:
score: 0
Accepted
time: 77ms
memory: 37292kb
input:
499 2013917 8399426 8383957 711026 6665904 1801413 4212743 7667353 1563880 9508350 5055783 2938456 1420474 597196 7098902 4861061 1824713 8373075 9222318 2465260 2078220 3487165 170713 7552076 3664375 3857312 5104701 8178526 8064615 4021518 3548850 6425637 2588875 7883832 2063342 8254970 8405006 157...
output:
256
result:
ok single line: '256'
Test #34:
score: 0
Accepted
time: 82ms
memory: 40340kb
input:
499 8663167 4628832 3192083 216731 6220205 45354 2308163 4681181 3661493 1097231 5021346 2125421 7705421 8453634 3550235 8195599 2174748 7044552 7637568 4755972 33906 1656871 8406600 8855737 4726103 9196559 9575333 6286649 1912428 1098066 7276536 2512362 104297 8344411 1557211 3321029 3430577 164826...
output:
264
result:
ok single line: '264'
Test #35:
score: 0
Accepted
time: 86ms
memory: 39996kb
input:
499 6291510 1967953 2070815 4695581 6781427 3244170 5672219 6820026 653477 9281226 6096228 808061 6953429 5688563 449287 8766803 4588296 920053 7095246 3338527 3841745 4699728 5860056 1639937 5921129 8279748 9354978 556554 5643767 6654450 5524998 8181725 1656696 8176842 221683 4746851 1967707 361058...
output:
261
result:
ok single line: '261'
Test #36:
score: 0
Accepted
time: 86ms
memory: 44804kb
input:
749 9998146 9990307 9998050 9975346 9985120 9975271 9994030 9986437 9993283 9995293 9996691 9982027 9976183 9998917 9993430 9999876 9995410 9995520 9992776 9978871 9996466 9989881 9997021 9993541 9997987 9977236 9998580 9989346 9991387 9976936 9978331 9980641 9978190 9978076 9990286 9982483 9994843 ...
output:
375
result:
ok single line: '375'
Test #37:
score: 0
Accepted
time: 81ms
memory: 39332kb
input:
749 9999278 9999910 9993783 9999304 9999936 9999514 9996581 9999992 9999674 9997685 9997839 9999382 9995525 9999762 9999270 9999788 9999832 9999414 9999503 9999362 9994901 9996005 9999506 9997475 9999338 9997523 9999618 9995441 9996651 9999736 9999258 9999646 9999766 9997829 9999374 9999960 9999968 ...
output:
375
result:
ok single line: '375'
Test #38:
score: 0
Accepted
time: 86ms
memory: 43456kb
input:
749 9999998 9999998 9999998 9999998 9998369 9999998 9999998 9999998 9999998 9999998 9999998 9999998 9999998 9996411 9999998 9999998 9995391 9999998 9994961 9999998 9999633 9995255 9999998 9995403 9999998 9995981 9999998 9999998 9994919 9994953 9999998 9999998 9996785 9999911 9997253 9999998 9996795 ...
output:
375
result:
ok single line: '375'
Test #39:
score: 0
Accepted
time: 72ms
memory: 39528kb
input:
749 3980498 5847674 9639248 2926742 8166507 941204 2771841 5462330 813020 8949254 8875649 3622589 2415221 4642041 547967 740720 1755410 5717570 9897224 8767191 625919 5666891 8167724 4345100 1121847 4546557 7995927 3922221 7299257 2214244 570074 5048324 62741 876209 5971157 5491043 7690079 2134017 7...
output:
384
result:
ok single line: '384'
Test #40:
score: 0
Accepted
time: 79ms
memory: 42556kb
input:
749 7688801 3658961 8570504 8584619 53354 8405430 427778 5180142 3345120 353333 2966633 5969453 863507 2090766 4844483 5263181 9100853 3006506 1898046 3151436 3872714 3555032 6786804 3315558 1905452 4295681 8192585 7468628 6747899 3925859 7384574 1225298 1216806 8799719 9266129 7626947 3528335 37722...
output:
401
result:
ok single line: '401'
Test #41:
score: 0
Accepted
time: 80ms
memory: 39320kb
input:
749 2020273 5997169 3287149 7452277 8254813 2562991 901159 3943450 102700 476656 5774740 4405320 1255488 7068180 3252978 5873922 409831 8831530 4695541 9836827 3532810 5744051 9422208 6358291 5331220 1877128 2262073 8120731 7229083 6499260 1395301 3896710 4335709 7806709 9078343 4800186 1187886 9097...
output:
377
result:
ok single line: '377'
Test #42:
score: 0
Accepted
time: 82ms
memory: 38700kb
input:
749 9930867 7300598 2580096 8389343 3501501 9644652 366438 3228965 1293424 9756938 2046666 9864460 4565935 3761222 4807524 2066503 7960263 6577322 7353140 5480202 6600166 9380422 5482824 8920602 8242729 7380402 4707130 1907350 7569266 891778 8481856 3871973 4109302 5499258 9770068 2492247 2893761 64...
output:
720
result:
ok single line: '720'
Test #43:
score: -100
Wrong Answer
time: 86ms
memory: 38088kb
input:
749 3624116 9467508 5287962 5910195 4914191 8126121 2291757 8137048 1357416 4390 4888928 9967728 4608564 9864969 7866171 8609331 214537 1876128 2284423 7945136 9905448 7032084 631582 2835317 1308572 1235651 9284901 2623735 3000962 6728977 4487704 5012177 3875624 8492043 814546 7654973 3939435 897457...
output:
702
result:
wrong answer 1st lines differ - expected: '704', found: '702'