QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450669#5554. Breeding BugsEbiarat#WA 61ms84228kbC++202.3kb2024-06-22 16:54:512024-06-22 16:54:52

Judging History

你现在查看的是最新测评结果

  • [2024-06-22 16:54:52]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:84228kb
  • [2024-06-22 16:54:51]
  • 提交

answer

#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <sstream>
#include <ctime>
#include <iterator>
#include <string.h>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <fstream>
#include <assert.h>
#include <numeric>
#include <complex>
#include <random>
#include <utility>



#define IOS ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a) - 1; i>=(b);i--)
#define rep(i,n) FOR(i,0,n)
#define PB push_back
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define VI vector<int>
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VL vector<long long >
#define FILL(a, value) memset(a, value, sizeof(a))
const int nax = 2 * (int)1e5 + 147;
 
using namespace std;
 
const int MOD = 998244353;
const int INF = 1e9 +47 ;
const long long LINF = (long long)1e18 + 4747;
 
typedef long long LL;
const double EPS=1e-6;

int p[(int)1e7 * 2 + 4];
int cc[770 * 770];
vector<int > g[770];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++ )
    {
        cin >> a[i];
    }
    for(int i = 0; i <=1e7 * 2;i ++ )p[i] = true;
    p[0] = p[1] = false;
    int mx =(int)1e7;
    for (int i = 2; i * i <= mx; i++) {
        if(p[i]) {
            for (int j = i * i; j <= mx; j += i) {
                p[j] = false;
            }
        }
    }
    for(int i = 0;i <n;i ++ )
    {
        for(int j = i + 1;j < n;j ++ ) {
            if(p[a[i] + a[j]] == true) {
                cc[i]++;
                cc[j]++;
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }
    set<pair<int,int>>s;
    for(int i = 0;i < n;i ++) {
        s.insert({cc[i],i});
    }
    int ans = 0;
    while(!s.empty() && s.rbegin()->first > 0) {
        auto v= *s.rbegin();
        s.erase(*s.rbegin());
        ans++;
        for(auto x : g[v.second]) {
            if(s.count({cc[x],x})) {
                s.erase({cc[x],x});
                cc[x]--;
                s.insert({cc[x],x});
            }
        }
    }
    cout << n - ans << '\n';
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 47ms
memory: 84228kb

input:

8
1 2 3 4 5 6 7 8

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 51ms
memory: 81900kb

input:

5
7 13 2 2 4

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 49ms
memory: 84004kb

input:

2
1 1

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 46ms
memory: 82664kb

input:

3
1 2 1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 61ms
memory: 83576kb

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: -100
Wrong Answer
time: 60ms
memory: 83160kb

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:

372

result:

wrong answer 1st lines differ - expected: '375', found: '372'