提出 #53149404


ソースコード 拡げる

/*
  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(0<=h&&h<n);
            assert((curMsk&(1LL<<h))==0);
            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);

    lli tim = 0,tr=-2,fal=-3;
    auto chk=[&](const lli exc,const lli rest)->bool{
        vector<vi> vis(M,vi(1LL<<n,-1));
        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);

    if(chk(-1,tot))
    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
コード長 6708 Byte
結果 WA
実行時間 692 ms
メモリ 11996 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:161:5: note: in expansion of macro ‘dbg’
  161 |     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:209:13: note: in expansion of macro ‘dbg’
  209 |             dbg(r,z,resp);
      |             ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:211:17: note: in expansion of macro ‘dbg’
  211 |                 dbg("passed",r,z);
      |                 ^~~
Main.cpp:23:26: warning: statement has no effect [-Wunused-value]
   23 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:215:9: note: in expansion of macro ‘dbg’
  215 |         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 3708 KiB
sample01.txt AC 1 ms 3820 KiB
sample02.txt AC 1 ms 3828 KiB
testcase00.txt AC 1 ms 4240 KiB
testcase01.txt AC 1 ms 4116 KiB
testcase02.txt AC 2 ms 4144 KiB
testcase03.txt AC 3 ms 4856 KiB
testcase04.txt AC 4 ms 4612 KiB
testcase05.txt AC 3 ms 4696 KiB
testcase06.txt AC 9 ms 5172 KiB
testcase07.txt AC 12 ms 5228 KiB
testcase08.txt AC 10 ms 5236 KiB
testcase09.txt AC 21 ms 5752 KiB
testcase10.txt AC 17 ms 5804 KiB
testcase11.txt AC 25 ms 5740 KiB
testcase12.txt AC 40 ms 6288 KiB
testcase13.txt AC 38 ms 6292 KiB
testcase14.txt AC 36 ms 6284 KiB
testcase15.txt AC 67 ms 6968 KiB
testcase16.txt WA 66 ms 6812 KiB
testcase17.txt AC 62 ms 6868 KiB
testcase18.txt AC 90 ms 7304 KiB
testcase19.txt AC 91 ms 7436 KiB
testcase20.txt AC 81 ms 7348 KiB
testcase21.txt AC 128 ms 8012 KiB
testcase22.txt AC 135 ms 7924 KiB
testcase23.txt AC 130 ms 7932 KiB
testcase24.txt AC 181 ms 8380 KiB
testcase25.txt AC 182 ms 8336 KiB
testcase26.txt AC 156 ms 8364 KiB
testcase27.txt AC 226 ms 8920 KiB
testcase28.txt AC 231 ms 8900 KiB
testcase29.txt AC 234 ms 8848 KiB
testcase30.txt AC 286 ms 9420 KiB
testcase31.txt AC 289 ms 9480 KiB
testcase32.txt AC 289 ms 9372 KiB
testcase33.txt AC 360 ms 9852 KiB
testcase34.txt AC 350 ms 10036 KiB
testcase35.txt AC 356 ms 10104 KiB
testcase36.txt AC 445 ms 10380 KiB
testcase37.txt AC 425 ms 10320 KiB
testcase38.txt AC 430 ms 10436 KiB
testcase39.txt AC 492 ms 10908 KiB
testcase40.txt AC 506 ms 10852 KiB
testcase41.txt AC 494 ms 10916 KiB
testcase42.txt AC 595 ms 11516 KiB
testcase43.txt AC 601 ms 11532 KiB
testcase44.txt AC 660 ms 11604 KiB
testcase45.txt AC 692 ms 11976 KiB
testcase46.txt AC 683 ms 11996 KiB
testcase47.txt AC 680 ms 11880 KiB
testcase48.txt AC 110 ms 5216 KiB
testcase49.txt AC 39 ms 4148 KiB
testcase50.txt AC 278 ms 7424 KiB
testcase51.txt AC 2 ms 4080 KiB
testcase52.txt WA 13 ms 4296 KiB
testcase53.txt AC 27 ms 4948 KiB
testcase54.txt AC 1 ms 4040 KiB
testcase55.txt AC 1 ms 3944 KiB
testcase56.txt AC 2 ms 4160 KiB
testcase57.txt AC 9 ms 4704 KiB
testcase58.txt AC 3 ms 4868 KiB