QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232034#7185. Poor StudentsikefumyWA 6ms4496kbC++205.0kb2023-10-29 19:21:432023-10-29 19:21:44

Judging History

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

  • [2023-10-29 19:21:44]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4496kb
  • [2023-10-29 19:21:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int n, k;
ll c[50010][11];
set<pli> srt[11], es[11][11];
ll d[11], pre[11], e[11][11];
int stsrt[11], stue[11][11];
int s[50010], t[11];

// mode 0 : 消去 1 : 追加
void update_edge(int stu, int te, int mode) {
    if (c[stu][te] > 0) {
        if (mode) srt[te].insert({c[stu][te], stu});
        else srt[te].erase({c[stu][te], stu});
    }

    rep (i, k) {
        if (c[stu][te] * c[stu][i] < 0) {
            int x = te, y = i;
            if (c[stu][x] > 0) swap(x, y);
            if (mode) es[x][y].insert({c[stu][x] + c[stu][y], stu});
            else es[x][y].erase({c[stu][x] + c[stu][y], stu});
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n >> k;
    rep (i, n) rep (j, k) cin >> c[i][j], srt[j].insert({c[i][j], i});
    rep (i, k) cin >> t[i];

    // グラフの初期化
    rep (i, n) s[i] = 1;
    rep (i, k) rep (j, k) e[i][j] = linf;
    rep (i, k) {
        if (srt[i].empty()) d[i] = linf;
        else d[i] = srt[i].begin() -> first, stsrt[i] = srt[i].begin() -> second;
        pre[i] = -1;
    }

    ll ans = 0;
    rep (_, n) {
        // 最短距離の導出
        rep (i, k) {
            rep (x, k) {
                rep (y, k) {
                    if (chmin(d[y], d[x] + e[x][y])) pre[y] = x;
                }
            }
        }
        // パスの復元
        vector<int> path = {0};
        rep (i, k) {
            if (t[i] > 0) path[0] = i;
        }

        rep (i, k) {
            if (d[path[0]] > d[i] && t[i] > 0) path[0] = i;
        }
        while (pre[*path.rbegin()] != -1) path.push_back(pre[*path.rbegin()]);
        ans += d[path[0]];
        t[path[0]]--;
        reverse(all(path));

        // 辺の張り直し
        // 始点だけ特殊
        int u = path[0], stu = stsrt[u], v = 0;
        update_edge(stu, u, 0);
        c[stu][u] *= -1;
        update_edge(stu, u, 1);
        s[stu] = 0;
        rep (i, k) {
            if (c[stu][i] > 0) srt[i].erase({c[stu][i], stu});
        }

        rep (i, 1, path.size()) {
            v = path[i];
            stu = stue[u][v];
            update_edge(stu, u, 0);
            update_edge(stu, v, 0);
            c[stu][u] *= -1;
            c[stu][v] *= -1;
            update_edge(stu, u, 1);
            update_edge(stu, v, 1);
            u = v;
        }

        rep (i, k) {
            if (srt[i].empty()) d[i] = linf;
            else d[i] = srt[i].begin() -> first, stsrt[i] = srt[i].begin() -> second;
            pre[i] = -1;
        }

        rep (i, k) {
            rep (j, k) {
                if (es[i][j].empty()) e[i][j] = linf;
                else e[i][j] = es[i][j].begin() -> first, stue[i][j] = es[i][j].begin() -> second;
            }
        }
    }

    cout << ans << endl;
}

详细

Test #1:

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

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12

result:

ok answer is '12'

Test #2:

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

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8

result:

ok answer is '8'

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 4496kb

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:

66128

result:

wrong answer expected '92039', found '66128'