QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#651330#9457. Prime Setucup-team093AC ✓37ms18104kbC++201.6kb2024-10-18 17:37:342024-10-18 17:37:35

Judging History

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

  • [2024-10-18 17:37:35]
  • 评测
  • 测评结果:AC
  • 用时:37ms
  • 内存:18104kb
  • [2024-10-18 17:37:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=3100,MAXM=2e6+1;
int T,n,k;
int a[MAXN],f[MAXM],ru[MAXN],id[MAXN],vis[MAXN];
vector<int> p[MAXN];
bool cmp(int x, int y) {
  return ru[x]<ru[y];
}
void solve() {
  cin >> n >> k;
  for (int i=1; i<=n; i++) {
    cin >> a[i];
    id[i]=i;
    vis[i]=0;
    p[i].clear();
    ru[i]=0;
  }
  for (int i=1; i<=n; i++) {
    for (int j=i+1; j<=n; j++) {
      if (!f[a[i]+a[j]]) {
        p[i].push_back(j);
        p[j].push_back(i);
        ru[i]++,ru[j]++;
      }
    }
  }
  sort(id+1,id+n+1,cmp);
  int ans=0,sum=0;
  for (int x=1; x<=n; x++) {
      int i=id[x];
      if (!k) {
        break;
      }
      if (p[i].empty() || vis[i]) {
        continue;
      }
      int min1=1e9,min2=0;
      for (int v : p[i]) {
        if (!vis[v] && ru[v]<min1) {
          min1=ru[i];
          min2=v;
        }
      }
      if (!min2) {
        vis[i]=1;
        for (int v : p[i]) {
          ru[v]--;
        }
        sum++;
        continue;
      }
      vis[i]=vis[min2]=1;
      for (int v : p[i]) {
        ru[v]--;
      }
      for (int v : p[min2]) {
        ru[v]--;
      }
      ans+=2;
      k--;
  }
  //cout<< ans << " " << sum << " " << k << "\n";
  ans+=min(k,sum);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
    cin.tie(0);
  cin >> T;
  f[1]=1;
  for (int i=2; i<MAXM; i++) {
      if (!f[i]) {
        for (int j=i*2; j<MAXM; j+=i) {
          f[j]=1;
        }
      }
  }
  while (T--) {
    solve();
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 11464kb

input:

4
4 2
2 3 4 5
5 3
3 4 12 3 6
6 3
1 3 6 8 1 1
1 0
1

output:

4
3
6
0

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 37ms
memory: 18104kb

input:

110
3 3
2 2 2
3 1
1 1 1
3 2
1 1 1
3 3
1 1 1
4 2
1 1 1 1
10 7
1 1 1 2 4 6 8 10 12 14
18 1
10 5 9 4 10 7 2 4 9 1 6 1 4 9 2 4 9 7
19 5
1 6 1 8 8 1 5 10 9 2 10 2 1 9 6 10 4 3 6
14 4
6 6 8 9 5 3 4 9 2 2 1 10 10 1
15 10
5 4 2 4 10 1 8 4 10 3 10 3 7 10 4
17 5
10 7 2 4 3 1 10 8 2 8 3 4 1 1 1 1 1
20 6
8 4 6 ...

output:

0
2
3
3
4
8
2
10
8
15
10
12
10
10
12
16
10
10
12
16
14
13
13
14
17
0
19
12
12
11
16
10
19
2
12
10
5
14
10
10
13
2
18
2
4
4
11
8
11
8
0
10
10
0
10
0
8
15
12
11
13
18
10
17
9
8
20
19
13
6
4
6
11
9
13
11
6
2
8
12
17
14
6
2
20
2
18
17
6
2
10
0
7
16
2
2
0
2
18
14
11
8
4
6
0
19
890
204
2746
2372

result:

ok 110 lines

Extra Test:

score: 0
Extra Test Passed