Submission #134397

#TimeUsernameProblemLanguageResultExecution timeMemory
134397dualityBitaro’s Party (JOI18_bitaro)C++11
100 / 100
1602 ms197060 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- vi adjList[100000],C; vpii best[100000]; int del[100000]; int dp[100000]; int main() { int i,j,k; int N,M,Q; int S,E,T,Y; scanf("%d %d %d",&N,&M,&Q); for (i = 0; i < M; i++) scanf("%d %d",&S,&E),adjList[E-1].pb(S-1); for (i = 0; i < N; i++) { best[i].pb(mp(0,i)); for (j = 0; j < adjList[i].size(); j++) { int v = adjList[i][j]; for (k = 0; k < best[v].size(); k++) best[i].pb(mp(best[v][k].first+1,best[v][k].second)); } int c = 0; sort(best[i].begin(),best[i].end(),greater<pii>()); for (j = 0; j < best[i].size(); j++) { if (!del[best[i][j].second]) best[i][c++] = best[i][j],del[best[i][j].second] = 1; } for (j = 0; j < c; j++) del[best[i][j].second] = 0; best[i].resize(min(80,c)); } for (i = 0; i < Q; i++) { scanf("%d %d",&T,&Y),T--; C.resize(Y); for (j = 0; j < Y; j++) scanf("%d",&C[j]),C[j]--,del[C[j]] = 1; for (j = 0; j < best[T].size(); j++) { if (!del[best[T][j].second]) break; } if (j < best[T].size()) printf("%d\n",best[T][j].first); else { for (j = 0; j <= T; j++) { dp[j] = del[j] ? -1e9:0; for (k = 0; k < adjList[j].size(); k++) dp[j] = max(dp[j],dp[adjList[j][k]]+1); } printf("%d\n",(dp[T] < 0) ? -1:dp[T]); } for (j = 0; j < Y; j++) del[C[j]] = 0; } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:70:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:72:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k = 0; k < best[v].size(); k++) best[i].pb(mp(best[v][k].first+1,best[v][k].second));
                         ~~^~~~~~~~~~~~~~~~
bitaro.cpp:76:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < best[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~
bitaro.cpp:86:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < best[T].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~
bitaro.cpp:89:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (j < best[T].size()) printf("%d\n",best[T][j].first);
             ~~^~~~~~~~~~~~~~~~
bitaro.cpp:93:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (k = 0; k < adjList[j].size(); k++) dp[j] = max(dp[j],dp[adjList[j][k]]+1);
                             ~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&N,&M,&Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:67:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < M; i++) scanf("%d %d",&S,&E),adjList[E-1].pb(S-1);
                             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:83:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&T,&Y),T--;
         ~~~~~~~~~~~~~~~~~~~~^~~~
bitaro.cpp:85:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for (j = 0; j < Y; j++) scanf("%d",&C[j]),C[j]--,del[C[j]] = 1;
                                 ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...