QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#29269#3588. Hamilton - The Musical19780215WA 103ms12660kbC++114.2kb2022-04-16 14:56:592022-04-28 14:26:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-28 14:26:28]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:12660kb
  • [2022-04-16 14:56:59]
  • 提交

answer

#define mul_cases false

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cstring>
#include <queue>
#define int long long
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

bool MEM1;

const int buf_siz = 1 << 12;

char inbuf[buf_siz], *p1, *p2;

inline char gc()
{
    if (p1 == p2)
        p1 = inbuf, p2 = p1 + fread(inbuf, 1, buf_siz, stdin);
    return p1 == p2 ? EOF : *p1++;
}

int read()
{
    int x = 0, f = 1;
    char ch = gc();
    for (; !isdigit(ch); ch = gc())
        if (ch == '-')
            f = -1;
    for (; isdigit(ch); ch = gc())
        x = x * 10 + ch - '0';
    return x * f;
}

namespace solve
{
    const int maxn = 1010;
    const int inf = 1e9;

    struct Dinic
    {
        struct edge
        {
            int x, y, cap, flow, cost;
        };
        vector<edge> edges;
        vector<int> e[maxn];

        inline void add(int x, int y, int cap, int cost)
        {
            // cerr << x << " " << y << " " << cap << " " << cost << endl;
            edges.push_back({x, y, cap, 0, cost});
            edges.push_back({y, x, 0, 0, -cost});
            int m = edges.size();
            e[x].push_back(m - 2), e[y].push_back(m - 1);
        }
        ll dis[maxn];
        int vis[maxn], cur[maxn], s, t;

        bool spfa()
        {
            queue<int> q;
            memset(dis, 0x3f, sizeof(int) * (t + 2)), memset(vis, 0, sizeof(int) * (t + 2));
            dis[s] = 0, vis[s] = 1, q.push(s);
            while (!q.empty())
            {
                int x = q.front();
                q.pop(), vis[x] = 0;
                for (int i : e[x])
                {
                    auto &k = edges[i];
                    if (k.cap - k.flow > 0 && k.cost + dis[x] < dis[k.y])
                    {
                        dis[k.y] = dis[x] + k.cost;
                        if (!vis[k.y])
                            q.push(k.y), vis[k.y] = 1;
                    }
                }
            }
            return dis[t] < 1e8;
        }

        ll mcmf;

        int dfs(int x, int lim)
        {
            if (x == t || lim == 0)
                return lim;
            vis[x] = 1;
            int res = 0, f;
            for (int &i = cur[x]; i < (int)e[x].size(); i++)
            {
                auto &k = edges[e[x][i]];
                if (dis[x] + k.cost != dis[k.y] || vis[k.y] || (f = dfs(k.y, min(lim, k.cap - k.flow))) == 0)
                    continue;
                mcmf += 1ll * f * k.cost;
                k.flow += f, edges[e[x][i] ^ 1].flow -= f, res += f, lim -= f;
                if (lim == 0)
                    break;
            }
            vis[x] = 0;
            return res;
        }

        ll dinic(int s_, int t_)
        {
            s = s_, t = t_;
            mcmf = 0;
            int ans = 0;
            while (spfa())
                memset(cur, 0, sizeof(int) * (t + 2)), ans += dfs(s, 1 << 25);
            return mcmf;
        }
    } G;
    
    int e[maxn][maxn], n;

    void main()
    {
        n = read();
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                e[i][j] = read();
        int R = n / 2, L = n - R;
        R = L;
        int S = L + R + 1, T = S + 1;
        for (int i = 1; i <= L; i++)
            G.add(S, i, 1, 0);
        for (int i = 1; i <= R; i++)
            G.add(i + L, T, 1, 0);
        for (int i = 1; i <= L; i++)
        {
            for (int j = 1; j <= R; j++)
            {
                int x = (i - 1) * 2 + 1;
                int y = (j - 1) * 2 + 1;
                G.add(i, j + L, 1, e[x][y - 1] + e[x][y + 1]);
            }
        }
        cout << G.dinic(S, T) << endl;
    }
}


bool MEM2;

signed main()
{
#ifdef local
    cerr << "memory : " << abs(&MEM1 - &MEM2) / 1024. / 1024 << " mb" << endl;
#endif

    int cases = 1;

    if (mul_cases)
        cin >> cases;

    while (cases--)
        solve::main();

#ifdef local
    cerr << "time : " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
#endif

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3692kb

input:

4
0 3 2 13
3 0 8 9
2 8 0 5
13 9 5 0

output:

16

result:

ok single line: '16'

Test #2:

score: -100
Wrong Answer
time: 103ms
memory: 12660kb

input:

455
0 71154840 37432199 724743679 761809953 949789082 725973225 28455138 924138757 574256423 297516452 223475432 693485895 699629134 731875885 697643903 595490098 206757530 965177624 178416136 103223719 474785234 322984824 510200285 656185874 993023494 973542087 511171280 465648799 836547414 8145240...

output:

6759214189

result:

wrong answer 1st lines differ - expected: '25287020967', found: '6759214189'