QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93539#4229. GCD HarmonylinakWA 4ms5728kbC++171.0kb2023-04-01 12:00:002023-04-01 12:00:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-01 12:00:02]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5728kb
  • [2023-04-01 12:00:00]
  • 提交

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=2; i<=100; i++){
        dp[x][i]=k[x]%i?i:0;
        for(int u:adj[x]){
            if(!vi[u]){
                auto t=rec(u);
                int r=1e9;
                for(int v:kdj[i]) r=min(t[v],r);
                dp[x][i]+=r;
            }
        }
    }
    return dp[x];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    for(int i=2; i<=100; i++){
        for(int j=2; j<=100; j++) if(gcd(i,j)>1) kdj[i].push_back(j);
    }
    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: 0
Wrong Answer
time: 4ms
memory: 5728kb

input:

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

output:

0

result:

wrong answer 1st lines differ - expected: '6', found: '0'