QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375616#4229. GCD Harmony8BQube#WA 8ms196868kbC++201.7kb2024-04-03 14:13:242024-04-03 14:13:24

Judging History

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

  • [2024-04-03 14:13:24]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:196868kb
  • [2024-04-03 14:13:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())

const int C = 100;
int arr[5005], sz[5005];
int dp[5005][10005], tmp[10005], n;
//bitset<10005> table[10005];
vector<int> G[5005];

void dfs(int u, int f) {
    sz[u] = 1;
    for (int i : G[u])
        if (i != f) {
            dfs(i, u);
            sz[u] += sz[i];
        }
    int up = max(C, sz[u] * 2);
    iota(dp[u] + 2, dp[u] + up + 1, 2);
    dp[u][arr[u]] = 0; 
    for (int i : G[u])
        if (i != f) {
            fill_n(tmp + 1, C, 2 * n + 1);
            for (int j = 2; j <= C; ++j) {
                int val = 2 * n + 1;
                for (int k = j; k <= max(C, sz[i] * 2); k += j)
                    val = min(val, dp[i][k]);
                for (int k = j; k <= max(C, sz[u] * 2); k += j)
                    tmp[k] = min(tmp[k], val);
            }
            for (int j = 2; j <= up; ++j)
                dp[u][j] += tmp[j], dp[u][j] = min(dp[u][j], 2 * n + 1);
        }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    /*for (int i = 2; i <= 10000; ++i)
        for (int j = i; j <= 10000; ++j) {
            int a = i, b = j;
            if (b % a == 0) table[i][j] = table[j][i] = 1;
            else table[i][j] = table[j][i] = table[b % a][a];
        }*/
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
    dfs(1, 1);
    cout << *min_element(dp[1] + 2, dp[1] + 2 * n + 1) << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

input:

6
5
6
3
4
9
12
1 2
1 3
1 4
1 6
3 5

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

3
1
2
3
3 1
2 3

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

13
2
5
5
5
5
5
5
3
3
3
3
3
3
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

15

result:

ok single line: '15'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

9
2
5
5
5
5
3
3
3
3
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9

output:

14

result:

ok single line: '14'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

8
13
13
13
2
13
13
13
13
1 2
1 3
1 4
1 5
1 6
1 7
1 8

output:

13

result:

ok single line: '13'

Test #6:

score: -100
Wrong Answer
time: 8ms
memory: 196868kb

input:

5000
59
25
51
26
33
99
2
13
29
58
5
47
96
83
63
22
69
89
41
90
20
97
85
90
55
17
54
75
54
24
90
54
74
78
81
77
2
47
68
18
60
81
99
86
7
6
76
43
17
43
92
25
36
26
47
100
63
66
2
16
47
25
48
86
24
2
10
42
44
80
92
48
49
21
49
40
32
85
53
88
15
30
4
27
77
16
6
80
50
56
46
14
3
48
92
50
93
35
69
29
48
4...

output:

101

result:

wrong answer 1st lines differ - expected: '4778', found: '101'