QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#951619#7185. Poor StudentsStarrykillerCompile Error//C++263.2kb2025-03-26 14:52:552025-03-26 14:52:56

Judging History

This is the latest submission verdict.

  • [2025-03-26 14:52:56]
  • Judged
  • [2025-03-26 14:52:55]
  • Submitted

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever! 
#include <bits/stdc++.h>

using namespace std;

auto range(auto l, auto r) { return views::iota(l,r); }
auto rev=views::reverse;

_GLIBCXX_ALWAYS_INLINE void chmax(auto &a, auto b) { a=max(a,b); }
_GLIBCXX_ALWAYS_INLINE void chmin(auto &a, auto b) { a=min(a,b); }

using i64=int64_t;

struct node {
    int i; i64 w;
    bool operator<(const node& rhs) const {
        if (w!=rhs.w) return w<rhs.w;
        return i<rhs.i;
    }
};


#define _GLIBCXX_DEBUG
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
// int T; cin>>T;
int T=1;
while (T--) []{
    int n, k; cin>>n>>k;
    vector f(k,vector(k,set<node>()));
    vector a(k,0ll);
    
    auto bellman_ford=[&](vector<i64> p){
        int t=k;
        vector<i64> dis(k+1,1e18);
        vector<int> vis(k+1), pre(k+1);
        queue<int> q; 
        for (int i=0; i<k; ++i) vis[i]=1, q.emplace(i), pre[i]=i, dis[i]=p[i];
        while (size(q)) {
            int u=q.front(); q.pop(); vis[u]=0;
            // cerr<<u<<' '<<dis[u]<<'\n';
            for (auto v: range(0,k)) if (size(f[u][v])) {
                auto [_,w]=*begin(f[u][v]);
                if (dis[v]>dis[u]+w) {
                    dis[v]=dis[u]+w; pre[v]=u;
                    if (!vis[v]) q.emplace(v), vis[v]=1;
                }
            }
            if (a[u] && dis[u]<dis[t]) 
                dis[t]=dis[u], pre[t]=u;
        }
        vector<int> path;
        for (auto i=t; ; i=pre[i]) {
            path.emplace_back(i);
            if (pre[i]==i) break;
        }
        ranges::reverse(path); path.pop_back();
        // cerr<<dis[t]<<'\n';
        return make_pair(dis[t],path);
    };
    vector c(n,vector(k,0ll));
    for (auto &i: c)
        for (auto &j: i) cin>>j;
    for (auto &i: a) cin>>i;
    i64 ans=0;
    auto add=[&](int x, int y) {
        for (auto i: range(0,k)) if (i!=y) {
            if (c[x][i]>=c[x][y]){
                // cerr<<y<<' '<<i<<": "<<c[x][i]-c[x][y]<<'\n';

                f[y][i].emplace(x,c[x][i]-c[x][y]);
            }
        }
    };
    auto del=[&](int x, int y) {
        for (auto i: range(0,k)) if (i!=y) {
            if (c[x][i]>=c[x][y]) {
                // cerr<<y<<' '<<i<<": "<<c[x][i]-c[x][y]<<'\n';
                // assert(f[y][i].contains({x,c[x][i]-c[x][y]}));
                
                f[y][i].erase({x,c[x][i]-c[x][y]});
            }
        }
    };
    for (auto i: range(0,n)) {
        auto [delta,path]=bellman_ford(c[i]);
        vector<pair<int,int>> D, A;
        A.emplace_back(i,path.front());
        // cerr<<i<<" -> "<<path.front()<<'\n';
        for (size_t i=0; i+1<path.size(); ++i) {
            int x=path[i], y=path[i+1];
            auto L=begin(f[x][y])->i;
            // cerr<<L<<' '<<x<<" -> "<<y<<'\n';
            D.emplace_back(L,x);
            A.emplace_back(L,y);
        }
        // cerr<<"---------\n";
        for (auto [x,y]: A) add(x,y);
        for (auto [x,y]: D) del(x,y);
        ans+=delta; a[path.back()]--;
    }
    cout<<ans<<'\n';

}();
}

Details

answer.code: In lambda function:
answer.code:88:39: error: no match for call to ‘(main()::<lambda()>::<lambda(std::vector<long int>)>) (__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int, std::allocator<long long int> > >, std::vector<long long int, std::allocator<long long int> > >::value_type&)’
   88 |         auto [delta,path]=bellman_ford(c[i]);
      |                           ~~~~~~~~~~~~^~~~~~
answer.code:35:23: note: candidate: ‘main()::<lambda()>::<lambda(std::vector<long int>)>’
   35 |     auto bellman_ford=[&](vector<i64> p){
      |                       ^
answer.code:35:23: note:   no known conversion for argument 1 from ‘vector<long long int,allocator<long long int>>’ to ‘vector<long int,allocator<long int>>’
answer.code:94:31: error: ‘y’ was not declared in this scope
   94 |             auto L=begin(f[x][y])->i;
      |                               ^