QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#176949#7185. Poor StudentsHaccerKatWA 6ms4064kbC++206.7kb2023-09-12 11:48:022023-09-12 11:48:03

Judging History

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

  • [2023-09-12 11:48:03]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4064kb
  • [2023-09-12 11:48:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
template<typename T>
int SIZE(T (&t)){
    return t.size();
}

template<typename T, size_t N>
int SIZE(T (&t)[N]){
    return N;
}

string to_string(char t){
    return "'" + string({t}) + "'";
}

string to_string(bool t){
    return t ? "true" : "false";
}

string to_string(const string &t, int x1=0, int x2=1e9){
    string ret = "";
    for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
        ret += t[i];
    }
    return '"' + ret + '"';
}

string to_string(const char* t){
    string ret(t);
    return to_string(ret);
}

template<size_t N>
string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
    string ret = "";
    for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
        ret += t[i] + '0';
    }
    return to_string(ret);
}

template<typename T, typename... Coords>
string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);

template<typename T, typename S>
string to_string(const pair<T, S> &t){
    return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
}

template<typename T, typename... Coords>
string to_string(const T (&t), int x1, int x2, Coords... C){
    string ret = "[";
    x1 = min(x1, SIZE(t));
    auto e = begin(t);
    advance(e,x1);
    for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
        ret += to_string(*e, C...) + (i != _i ? ", " : "");
        e = next(e);
    }
    return ret + "]";
}

template<int Index, typename... Ts>
struct print_tuple{
    string operator() (const tuple<Ts...>& t) {
        string ret = print_tuple<Index - 1, Ts...>{}(t);
        ret += (Index ? ", " : "");
        return ret + to_string(get<Index>(t));
    }
};

template<typename... Ts>
struct print_tuple<0, Ts...> {
    string operator() (const tuple<Ts...>& t) {
        return to_string(get<0>(t));
    }
};

template<typename... Ts>
string to_string(const tuple<Ts...>& t) {
    const auto Size = tuple_size<tuple<Ts...>>::value;
    return print_tuple<Size - 1, Ts...>{}(t);
}

void dbgr(){;}
template<typename Heads, typename... Tails>
void dbgr(Heads H, Tails... T){
    cout << to_string(H) << " | ";
    dbgr(T...);
}

void dbgs(){;}
template<typename Heads, typename... Tails>
void dbgs(Heads H, Tails... T){
    cout << H << " ";
    dbgs(T...);
}

/*
formatted functions:
*/

/*
consider __VA_ARGS__ as a whole:
dbgv() prints values only
dbg() prints name and values
*/
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;

#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
//#define dbg(...)

/*
consider __VA_ARGS__ as a sequence of arguments:
dbgr() prints values only
dbgm() prints names and values
*/
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;

#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
// using u128 = __uint128_t;
// using i128 = __int128;
const int mod = 1000000007;
const int N = 50005;
const int K = 11;
const int LOG = 20;
const ll inf = 1e18;
const double eps = 1e-11;
int n, m, qq;
int c[N][K], a[K], nxt[K][K], adj[K][K], on[N];
ll d[K][K];
bool fl[N][K];
set<pi> s[K], sp[K][K];
void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        on[i] = 1;
        for (int j = 0; j < m; j++) {
            cin >> c[i][j];
            s[j].insert({c[i][j], i});
        }
    }
    
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    
    ll out = 0;
    auto flip = [&](int x, int y) {
        out += fl[x][y] ? -c[x][y] : c[x][y];
        fl[x][y] ^= 1;
        if (!fl[x][y]) {
            for (int i = 0; i < m; i++) {
                if (!fl[x][i]) sp[y][i].erase({c[x][i] - c[x][y], x});
                else sp[i][y].insert({c[x][y] - c[x][i], x});
            }
            
            if (on[x]) s[y].erase({c[x][y], x});
        }
        
        else {
            for (int i = 0; i < m; i++) {
                if (fl[x][i]) sp[i][y].erase({c[x][y] - c[x][i], x});
                else sp[y][i].insert({c[x][i] - c[x][y], x});
            }
            
            if (on[x]) s[y].insert({c[x][y], x});
        }
    };
    
    for (int iter = 0; iter < n; iter++) {
        // dbg(iter);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                ll w = (i == j ? 0 : inf);
                bool flag = 0;
                if (!sp[i][j].empty()) {
                    auto [cost, st] = *sp[i][j].begin(); 
                    w = min(w, (ll)cost);
                    flag = 1, adj[i][j] = st;
                }
                
                d[i][j] = w, nxt[i][j] = (flag ? j : -1);
            }
        }
        
        // dbg(d);
        for (int k = 0; k < m; k++) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    if (d[i][k] != inf && d[k][j] != inf && d[i][j] > d[i][k] + d[k][j]) {
                        d[i][j] = d[i][k] + d[k][j], nxt[i][j] = nxt[i][k];
                    }
                }
            }
        }
        
        // dbg(d);
        ll mn = inf;
        int x = -1, y = -1;
        for (int i = 0; i < m; i++) {
            auto [cost, st] = *s[i].begin();    
            ll mn2 = inf;
            int idx = -1;
            for (int j = 0; j < m; j++) {
                if (a[j] == 0) continue;
                if (d[i][j] < mn2) mn2 = d[i][j], idx = j;
            }
            
            if (cost + mn2 < mn) mn = cost + mn2, x = i, y = idx;
        }
        
        a[y]--;
        auto [cost, st] = *s[x].begin();
        // dbgm(st, x, y, out, mn);
        flip(st, x);
        while (x != y) {
            int z = nxt[x][y], stx = adj[x][z];
            flip(stx, x), flip(stx, z);
            x = z;
        }
        
        on[x] = 0;
        for (int i = 0; i < m; i++) {
            s[i].erase({c[st][i], st});
        }
    }
    
    cout << out << "\n";
}

int32_t main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

详细

Test #1:

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

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

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: 4064kb

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:

65231

result:

wrong answer expected '92039', found '65231'