Submission #859911

#TimeUsernameProblemLanguageResultExecution timeMemory
859911efedmrlrBitaro’s Party (JOI18_bitaro)C++17
7 / 100
2023 ms13292 KiB
#include <bits/stdc++.h>

using namespace std;

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl


#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
#pragma GCC optimize("O1,O2,O3")
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 2e5+5;
const int M = 2e5+5;
const int ALPH = 26;
const int LGN = 25;
const int MOD = 1e9+7;
const int B = 320;
int n,m,q;

vector<vector<int> > ins(N, vector<int>());
vector<vector<array<int,2> > > sts(N, vector<array<int,2> >());

inline void add_set(int tar, int st) {
    vector<array<int,2> > ret;
    set<int> founds;
    int i = 0, j = 0; 
    while(ret.size() < B+5 && i < sts[tar].size() && j < sts[st].size()) {
        if(sts[tar][i][0] > sts[st][j][0] + 1) {
            if(!founds.count(sts[tar][i][1]) )  ret.pb(sts[tar][i]);
            founds.insert(sts[tar][i][1]);
            i++;
        }
        else {
            if(!founds.count(sts[st][j][1]))  ret.pb({sts[st][j][0] + 1, sts[st][j][1]} );
            founds.insert(sts[st][j][1]);
            j++;
        }
    }
    while(ret.size() < B+5 && i < sts[tar].size()) {
        if(!founds.count(sts[tar][i][1]) )  ret.pb(sts[tar][i]);
        founds.insert(sts[tar][i][1]);
        i++;
    }
    while(ret.size() < B+5 && j < sts[st].size()) {
        if(!founds.count(sts[st][j][1]))  ret.pb({sts[st][j][0] + 1, sts[st][j][1]} );
        founds.insert(sts[st][j][1]);
        j++;
    }

    sts[tar] = ret;
}
vector<int> dp;
vector<int> vis;


inline void solve() {
    cin>>n>>m>>q;

    for(int i = 0; i<m; i++) {
        int s,e;
        cin>>s>>e;
        ins[e].pb(s);
    }
    for(int i = 1; i<=n; i++) {
        sts[i].pb({0, i});
        for(auto c : ins[i]) {
            add_set(i, c);
        }
    }
    for(int i = 0; i<q; i++) {
        int t, y;
        cin>>t>>y;
        vector<int> frn(y);
        for(int j = 0; j<y; j++) {
            cin>>frn[j];
        }
        
        if(y < B) {

            bool f = 1;
            int ind = 0;
            while(f && ind < sts[t].size()) {
                auto itr = lower_bound(frn.begin(), frn.end(), sts[t][ind][1]);
                if(itr != frn.end() && (*itr) == sts[t][ind][1]) {
                    ind++;
                }
                else {
                    f = 0;
                }
            }
            if(ind >= sts[t].size()) cout<<"-1\n";
            else {
                cout<<sts[t][ind][0]<<"\n";
            }
        }
        else {
            vis.assign(n+1, 0);
            for(int j = 0; j<y; j++) {
                vis[frn[j]] = 1; 
            }
            dp.assign(n+1, 0);
            dp[1] = vis[1] ? -1 : 0;
            for(int j = 2; j<=t; j++) {
                if(vis[j]) dp[j] = -1;
                for(auto c : ins[j]) {
                    if(dp[c] == -1) continue;
                    dp[j] = max(dp[j], dp[c] + 1);
                }
            }
            
            
            cout<<dp[t]<<"\n";
        }
        
    }


}
 
signed main() {

    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}

Compilation message (stderr)

bitaro.cpp: In function 'std::string to_string(std::string, int, int)':
bitaro.cpp:7:208: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
      |                                                                                                                                                                                                             ~~~^~~~~~~~~~
bitaro.cpp: In function 'void add_set(int, int)':
bitaro.cpp:39:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     while(ret.size() < B+5 && i < sts[tar].size() && j < sts[st].size()) {
      |                               ~~^~~~~~~~~~~~~~~~~
bitaro.cpp:39:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     while(ret.size() < B+5 && i < sts[tar].size() && j < sts[st].size()) {
      |                                                      ~~^~~~~~~~~~~~~~~~
bitaro.cpp:51:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     while(ret.size() < B+5 && i < sts[tar].size()) {
      |                               ~~^~~~~~~~~~~~~~~~~
bitaro.cpp:56:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     while(ret.size() < B+5 && j < sts[st].size()) {
      |                               ~~^~~~~~~~~~~~~~~~
bitaro.cpp: In function 'void solve()':
bitaro.cpp:94:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             while(f && ind < sts[t].size()) {
      |                        ~~~~^~~~~~~~~~~~~~~
bitaro.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |             if(ind >= sts[t].size()) cout<<"-1\n";
      |                ~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...