제출 #241589

#제출 시각아이디문제언어결과실행 시간메모리
241589MercenaryBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1453 ms248692 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;
int n , m , q;
vector<int> adj[maxn];
int f[maxn];
bool used[maxn];
bool tmp[maxn];

vector<ii> can[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m >> q;
    while(m--){
        int u , v;cin >> u >> v;adj[v].pb(u);
    }
    for(int i = 1 ; i <= n ; ++i){
        can[i].pb(mp(-1 , i));
        for(auto v : adj[i]){
            vector<ii> val;
            auto add = [&](vector<ii> & val , ii c){
                if(val.size() == 300 || tmp[c.second] == 1)return;
                val.pb(c);
                tmp[c.second] = 1;
            };
            int j = 0;
            for(auto & c : can[i]){
                while(j < can[v].size() && can[v][j] >= c)add(val , can[v][j++]);
                add(val , c);
            }
            while(j < can[v].size())add(val , can[v][j++]);
            can[i] = val;
            for(auto & c : val)tmp[c.second] = 0;
        }
        for(auto & c : can[i]){
            c.first++;
        }
    }
    while(q--){
        int u;cin >> u;
        int k;cin >> k;
        vector<int> val(k);
        for(auto & c : val){
            cin >> c;
            tmp[c] = 1;
        }
        if(k > 280){
            for(int i = 1 ; i <= u ; ++i){
                f[i] = (tmp[i] == 0 ? 0 : -1e9);
                for(auto v : adj[i]){
                    f[i] = max(f[i] , f[v] + 1);
                }
            }
            cout << max(f[u] , -1) << '\n';
        }else{
            int res = -1;
            for(auto & c : can[u]){
                if(tmp[c.second] == 0){
                    res = c.first;break;
                }
            }
            cout << res << '\n';
        }
        for(auto & c : val){
            tmp[c] = 0;
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'int main()':
bitaro.cpp:49:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 while(j < can[v].size() && can[v][j] >= c)add(val , can[v][j++]);
                       ~~^~~~~~~~~~~~~~~
bitaro.cpp:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(j < can[v].size())add(val , can[v][j++]);
                   ~~^~~~~~~~~~~~~~~
bitaro.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...