QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#34605#4229. GCD HarmonyYaoBIG#WA 2ms3684kbC++172.7kb2022-06-11 21:10:422022-06-11 21:10:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-11 21:10:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3684kb
  • [2022-06-11 21:10:42]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); i++)
#define revrep(i, a, n) for (auto i = n; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if(b < a) { a = b; return 1; } return 0; }
using namespace std;

template<class A, class B> string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A> string to_string(A v) {
    bool first = 1;
    string res = "{";
    for (const auto &x: v) {
        if (!first) res += ", ";
        first = 0;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template<class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.FI) + ", " + to_string(p.SE) + ")"; }

void debug_out() { cerr << endl; }
template<class Head, class... Tail> void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef ONLINE_JUDGE
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) if(0) puts("No effect.")
#endif

using ll = long long;
// using LL = __int128;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using db = double;
using ldb = long double;

const int inf = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;
    vi as(n);
    for (auto &x: as) cin >> x;
    vvi e(n);
    rep(i, 1, n - 1) {
        int x, y; cin >> x >> y;
        x--, y--;
        e[x].pb(y);
        e[y].pb(x);
    }

    vvi pfacs(n * 2 + 1);
    vi np(n * 2 + 1);
    rep(i, 2, n * 2) if(np[i] == 0) {
        for (int j = i; j <= n * 2; j += i) np[j] = 1, pfacs[j].pb(i);
    }
    vvi dp(n, vi(n * 2 + 1, inf));
    function<void(int, int)> dfs = [&](int now, int fa) {
        vi tmp(n * 2 + 1);
        for (auto v: e[now]) if (v != fa) {
            dfs(v, now);
            rep(i, 1, n * 2) tmp[i] += dp[v][i];
        }
        rep(i, 1, n * 2) {
            for (auto p: pfacs[i]) chmin(dp[now][i], tmp[p]);
            dp[now][i] += as[now] == i ? 0 : i;
        }
        rep(i, 1, n * 2) for (auto &p: pfacs[i]) chmin(dp[now][p], dp[now][i]);
    };
    dfs(0, -1);
    int ans = inf;
    rep(i, 2, n * 2) chmin(ans, dp[0][i]);
    printf("%d\n", ans);
    return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 3624kb

input:

3
1
2
3
3 1
2 3

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3624kb

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'