提出 #53136789


ソースコード 拡げる

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
*/
/*
  Credits -
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
  Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
  https://codeforces.com/contest/4/submission/150120627
*/

#include<atcoder/dsu>
#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
    #pragma GCC target ("sse,sse2,mmx")
    #pragma GCC optimize ("-ffloat-store")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define dbg(args...) 42;
    #define endl "\n"
#endif

// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second

using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.

// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

const lli INF = 0xFFFFFFFFFFFFFFFLL;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
lli T=1;
// cin>>T;
while(T--)
{
    lli n,m;
    cin>>n>>m;
    vector<vii> e(n);
    atcoder::dsu d(n);
    for(lli k=0;k<m;k++){
        lli u,v,c;
        cin>>u>>v>>c;
        u--;v--;
        if(d.same(u,v))
            continue;
        e[v].eb(ii{u,c});
        e[u].eb(ii{v,-c});

        d.merge(u,v);
    }

    const auto gps=d.groups();
    vi hei(n,-1);
    vii msks;
    vi maxAllowed;
    for(const auto &gp:gps){
        const lli root = gp[0];
        map<lli,lli> he;
        y_combinator([&](const auto &self,const lli u,const lli h)->void{
            if(he.count(u)){
                assert(he[u]==h);
                return;
            }
            he[u]=h;
            for(const auto &v:e[u])
                self(v.X,h+v.Y);
        })(root,0);

        lli minDis = INF,node=-1;
        for(const auto &u:he){
            if(minDis>u.Y){
                minDis=u.Y;
                node=u.X;
            }
        }

        lli curMsk=0,maxDist=-INF;
        for(const auto &u:he){
            const lli h=u.Y-minDis;
            hei[u.X]=h;
            assert((curMsk&(1LL<<h))==0);
            assert(0<=h&&h<n);
            curMsk|=1LL<<h;
            maxDist=max(maxDist,h);
        }
        msks.eb(ii{node,curMsk});
        maxAllowed.eb(n-maxDist);
    }
    dbg(msks);
    const lli tot = (1LL<<n)-1;
    const lli M = sz(gps);
    vector<vi> vis(M,vi(1LL<<n,-1));
    lli tim = 0,tr=-2,fal=-3;
    auto chk=[&](const lli exc,const lli rest)->bool{
        tim++;
        tr = tim;
        tim++;
        fal=tim;
        // dbg(exc,rest);
        return y_combinator([&](const auto &self,const lli idx,const lli rem)->bool{
            // dbg(exc,rest,idx,rem);
            if(idx==M)
                return rem==0;
            if(idx==exc)
                return self(idx+1,rem);
            auto &ans=vis[idx][rem];
            if(ans==tr||ans==fal)
                return ans;
            for(lli r=0;r<n;r++){
                const lli curMsk = msks[idx].Y<<r;
                dbg(msks[idx],r,curMsk);
                if((rem&curMsk)!=curMsk)
                    continue;
                if(self(idx+1,rem^curMsk)){
                    ans=tr;
                    return true;
                }
            }
            ans=fal;
            return false;
        })(0,rest);
    };

    vi ans(n,-1);
    dbg(hei);
    for(lli j=0;j<M;j++){
        const auto &z=msks[j];
        vi posRank;
        for(lli r=0;r<n;r++){
            const lli curMsk = z.Y<<r;
            if((tot&curMsk)!=curMsk)
                continue;
            const auto resp = chk(j,tot^curMsk);
            dbg(r,z,resp);
            if(resp){
                dbg("passed",r,z);
                posRank.eb(r);
            }
        }
        dbg(z,posRank);
        if(sz(posRank)!=1)
            continue;
        for(const auto &k:gps[j])
            ans[k]=posRank[0]+hei[k];
    }
    for(lli i=0;i<n;i++){
        if(ans[i]!=-1)
            ans[i]++;
        cout<<ans[i]<<" \n"[i+1==n];
    }
}   aryanc403();
    return 0;
}

提出情報

提出日時
問題 F - Estimate Order
ユーザ aryanc403
言語 C++ 20 (gcc 12.2)
得点 0
コード長 6679 Byte
結果 WA
実行時間 5 ms
メモリ 11956 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:162:5: note: in expansion of macro ‘dbg’
  162 |     dbg(msks);
      |     ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:198:5: note: in expansion of macro ‘dbg’
  198 |     dbg(hei);
      |     ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:207:13: note: in expansion of macro ‘dbg’
  207 |             dbg(r,z,resp);
      |             ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:209:17: note: in expansion of macro ‘dbg’
  209 |                 dbg("passed",r,z);
      |                 ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:213:9: note: in expansion of macro ‘dbg’
  213 |         dbg(z,posRank);
      |         ^~~
Main.cpp: In instantiation of ‘main()::<lambda(lli, lli)>::<lambda(const auto:54&, lli, lli)> [with auto:54 = std::reference_wrapper<y_combinator_result<main()::<lambda(lli, lli)>::<lambda(const auto:54&, lli, lli)> > >; lli = long long int]’:
Main.cpp:33:84:   required from ‘decltype(auto) y_combinator_result<Fun>::operator()(Args&& ...) [with Args = {int, const long long int&}; Fun = main()::<lambda(lli, lli)>::<lambda(const auto:54&, lli, lli)>]’
Main.cpp:194:11:   required from here
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:184:17: note: in expansion of macro ‘dbg’
  184 |                 dbg(msks[idx],r,curMsk);
      |                 ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 525
結果
AC × 3
AC × 60
WA × 2
セット名 テストケース
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt, testcase52.txt, testcase53.txt, testcase54.txt, testcase55.txt, testcase56.txt, testcase57.txt, testcase58.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 1 ms 3724 KiB
sample01.txt AC 1 ms 3772 KiB
sample02.txt AC 1 ms 3872 KiB
testcase00.txt AC 2 ms 4308 KiB
testcase01.txt AC 2 ms 4304 KiB
testcase02.txt AC 2 ms 4300 KiB
testcase03.txt AC 2 ms 4768 KiB
testcase04.txt AC 2 ms 4668 KiB
testcase05.txt AC 2 ms 4660 KiB
testcase06.txt AC 2 ms 5192 KiB
testcase07.txt AC 2 ms 5188 KiB
testcase08.txt AC 2 ms 5148 KiB
testcase09.txt AC 2 ms 5792 KiB
testcase10.txt AC 3 ms 5880 KiB
testcase11.txt AC 2 ms 5884 KiB
testcase12.txt AC 3 ms 6352 KiB
testcase13.txt AC 3 ms 6248 KiB
testcase14.txt AC 3 ms 6268 KiB
testcase15.txt AC 3 ms 6844 KiB
testcase16.txt WA 3 ms 6776 KiB
testcase17.txt AC 3 ms 6840 KiB
testcase18.txt AC 3 ms 7328 KiB
testcase19.txt AC 3 ms 7412 KiB
testcase20.txt AC 3 ms 7320 KiB
testcase21.txt AC 3 ms 7856 KiB
testcase22.txt AC 3 ms 7948 KiB
testcase23.txt AC 3 ms 7828 KiB
testcase24.txt AC 4 ms 8320 KiB
testcase25.txt AC 4 ms 8424 KiB
testcase26.txt AC 4 ms 8360 KiB
testcase27.txt AC 4 ms 8888 KiB
testcase28.txt AC 4 ms 8904 KiB
testcase29.txt AC 4 ms 8952 KiB
testcase30.txt AC 4 ms 9440 KiB
testcase31.txt AC 4 ms 9412 KiB
testcase32.txt AC 4 ms 9420 KiB
testcase33.txt AC 4 ms 10016 KiB
testcase34.txt AC 4 ms 9640 KiB
testcase35.txt AC 4 ms 9964 KiB
testcase36.txt AC 4 ms 10280 KiB
testcase37.txt AC 4 ms 10168 KiB
testcase38.txt AC 4 ms 10200 KiB
testcase39.txt AC 5 ms 10804 KiB
testcase40.txt AC 5 ms 10752 KiB
testcase41.txt AC 5 ms 10904 KiB
testcase42.txt AC 5 ms 11264 KiB
testcase43.txt AC 5 ms 11208 KiB
testcase44.txt AC 5 ms 11424 KiB
testcase45.txt AC 5 ms 11860 KiB
testcase46.txt AC 5 ms 11808 KiB
testcase47.txt AC 5 ms 11956 KiB
testcase48.txt AC 2 ms 5312 KiB
testcase49.txt AC 2 ms 4128 KiB
testcase50.txt AC 3 ms 7412 KiB
testcase51.txt AC 2 ms 3936 KiB
testcase52.txt WA 2 ms 4244 KiB
testcase53.txt AC 2 ms 4948 KiB
testcase54.txt AC 1 ms 3844 KiB
testcase55.txt AC 1 ms 3856 KiB
testcase56.txt AC 2 ms 4256 KiB
testcase57.txt AC 2 ms 4624 KiB
testcase58.txt AC 2 ms 4784 KiB