QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#878136#9692. Currencyucup-team3584#WA 1ms3840kbC++175.6kb2025-02-01 13:42:312025-02-01 13:42:31

Judging History

This is the latest submission verdict.

  • [2025-02-01 13:42:31]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-01 13:42:31]
  • Submitted

answer

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }

int dx4[] = {1,0,-1,0};
int dy4[] = {0,1,0,-1};

#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))

ll inf = 1001001001001001001;

template< typename flow_t >
struct Dinic {
    const flow_t INF;
    
    struct edge {
        int to;
        flow_t cap;
        int rev;
        bool isrev;
        int idx;
    };
    
    vector< vector< edge > > graph;
    vector< int > min_cost, iter;
    
    Dinic(int V) : INF(numeric_limits< flow_t >::max()), graph(V) {}
    
    void add_edge(int from, int to, flow_t cap, int idx = -1) {
        graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false, idx});
        graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true, idx});
    }
    
    bool bfs(int s, int t) {
        min_cost.assign(graph.size(), -1);
        queue< int > que;
        min_cost[s] = 0;
        que.push(s);
        while(!que.empty() && min_cost[t] == -1) {
            int p = que.front();
            que.pop();
            for(auto &e : graph[p]) {
                if(e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }
    
    flow_t dfs(int idx, const int t, flow_t flow) {
        if(idx == t) return flow;
        for(int &i = iter[idx]; i < graph[idx].size(); i++) {
            edge &e = graph[idx][i];
            if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while(bfs(s, t)) {
            iter.assign(graph.size(), 0);
            flow_t f = 0;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vc<int>a(n-1),b(n),c(n-1);
    Dinic<int>flow(n+1);
    int S = 0,T = n;
    rep(i,n-1) {
        cin >> a[i];
        flow.add_edge(S,i+1,a[i]);
    }
    rep(i,n) {
        cin >> b[i];
        if(i == 0) {
            flow.add_edge(i+1,T,b[i]);
            continue;
        }
        if(i+1 == n) {
            flow.add_edge(S,i,b[i]);
            continue;
        }
        flow.add_edge(i,i+1,b[i]);
        flow.add_edge(i+1,i,b[i]);
    }
    rep(i,n-1) {
        cin >> c[i];
        flow.add_edge(i+1,T,c[i]);
    }
    rep(i,m) {
        int U,V,C;
        cin >> U >> V >> C;
        flow.add_edge(V,U,C);
    }
    cout << flow.max_flow(S,T) << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

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

output:

13

result:

ok 1 number(s): "13"

Test #2:

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

input:

6 1000
601450612 529194719 287622428 350370653 2490001
267842805 909540874 518481012 265798837 15815265 20879824
142543426 589509572 795333485 574202609 686307559
5 5 368241593
3 4 501344156
3 2 881313477
5 3 877155507
3 3 638857659
3 5 60427320
3 1 888140066
1 1 820913164
3 2 656494106
5 2 48265697...

output:

1792008237

result:

ok 1 number(s): "1792008237"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

6 1000
939223353 592232256 204123592 697949032 283207645
247227259 860831362 710972139 170824074 510978702 280845746
896873779 377774668 7308887 326686740 179453061
2 3 997446049
2 3 519323074
4 1 939589279
2 5 98041599
4 4 869921378
3 3 558765317
1 2 483873583
5 1 33483163
3 3 270388480
4 4 5510784...

output:

2035324394

result:

ok 1 number(s): "2035324394"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

6 1000
959730384 933307890 88544023 434800479 519026844
598287106 88518137 220336188 475197957 997211224 13754116
615549399 359488030 322300660 426429747 456751804
2 1 37534981
2 1 826968454
4 5 736905082
2 2 392058437
3 2 148710959
5 3 340405411
4 3 756316407
1 1 989545410
1 4 953888522
1 2 4208087...

output:

-1516160550

result:

wrong answer 1st numbers differ - expected: '2778806746', found: '-1516160550'