QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93446#4229. GCD HarmonylinakWA 3ms5804kbC++171.1kb2023-03-31 21:08:492023-03-31 21:08:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 21:08:51]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5804kb
  • [2023-03-31 21:08:49]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

vector<vector<int>> dp(5001,vector<int>(101));
vector<int> adj[5001],k(5001),kdj[101];
bool vi[5001];

vector<int> rec(int x){
    vi[x]=true;
    for(int i=1; i<=100; i++){
        if(k[x]%i==0) dp[x][i]=0;
        else dp[x][i]=i;
    }
    for(int u: adj[x]){
        if(!vi[u]){
            vector<int> t=rec(u);
            for(int i=2; i<=100; i++){
                for(int v:kdj[i]) t[v]=min(t[i],t[v]);
            }
            for(int i=1; i<=100; i++) dp[x][i]+=t[i];
        }
    }
    return dp[x];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    for(int i=2; i<=100; i++){
        for(int j=i; j<=100; j+=i) kdj[j].push_back(i);
    }
    int a;
    cin>>a;
    for(int i=1; i<=a; i++) cin>>k[i];
    for(int i=1; i<a; i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    rec(1);
    int ans=1e9;
    for(int i=2; i<=100; i++) ans=min(ans,dp[1][i]);
    cout<<ans;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5736kb

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: 3ms
memory: 5620kb

input:

3
1
2
3
3 1
2 3

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5804kb

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:

21

result:

wrong answer 1st lines differ - expected: '15', found: '21'