제출 #139781

#제출 시각아이디문제언어결과실행 시간메모리
139781CaroLinda통행료 (IOI18_highway)C++14
51 / 100
376 ms262148 KiB
#include "highway.h" #include <bits/stdc++.h> #define debug #define lp(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define ll long long #define ff first #define ss second #define pb push_back #define mk make_pair const int MAXN = 9e4+ 10 ; const int MAXM = 13e4+10 ; using namespace std ; struct Edge { int j , id ; Edge(int j = 0 , int id = 0) : j(j) , id(id) {} } ; int n , m , S , T ; int edgePai[MAXN] , ini[MAXN] , fim[MAXN] ; pii edge[MAXM] ; vector<int> toAsk , possible ; ll rad , Prev ; vector<Edge> adj[MAXN] ; bool marc[MAXN] ; // -------------------------------- void prepareDfs() { memset(marc,false, sizeof marc) ; possible.resize(0) ; } void dfs(int x , ll depth , ll curRad , bool allowed[]) { if( depth == curRad ) possible.pb(x) ; marc[x] = true ; for( Edge e : adj[x] ) if( !marc[e.j] && allowed[e.id] ) { edgePai[e.j] = e.id ; dfs( e.j , depth+1, curRad , allowed ) ; } } int findSpecial(int s , bool allowed[] , ll curRad ) { if( curRad == 0 ) return s ; debug("%d %lld\n" , s ,curRad) ; lp(i,0,m) debug("%d " , allowed[i] == true ? 1 : 0) ; debug("\n") ; prepareDfs() ; dfs(s , 0 , curRad , allowed) ; int l = 0 , r = possible.size() - 1 , mid , best=0 ; while( l <= r ) { mid = (l+r)/2 ; lp(i,l,mid+1) toAsk[ edgePai[ possible[i] ] ] = 1 ; ll newTot = ask(toAsk) ; lp(i,l,mid+1) toAsk[ edgePai[ possible[i] ] ] = 0 ; if( newTot > Prev ) { r = mid - 1 ; best = mid ; } else l = mid+1 ; } return possible[best] ; } // -------------------------------- vector<int> grupo[2] ; void dfs(int x , int edgeId , int idx ) { for( Edge e : adj[x] ) if( edgeId != e.id ) { grupo[idx].pb(e.id) ; dfs(e.j,e.id, idx) ; } } bool allowed[MAXM] ; void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { m = U.size(); n = N ; lp(i,0,m) { int a = U[i] , b = V[i] ; adj[a].pb(Edge(b,i)) ; adj[b].pb(Edge(a,i)) ; toAsk.pb(0) ; allowed[i] = 1 ; edge[i] = mk(a,b) ; } Prev = ask(toAsk) ; rad = Prev/A ; int l = 0 , r = m-1 , mid , best =0 ; while(l<=r) { mid = (l+r)/2 ; lp(i,l,mid+1) toAsk[i] = 1 ; ll newTot = ask(toAsk) ; lp(i,l,mid+1) toAsk[i] = 0 ; if( newTot > Prev ) { r = mid - 1 ; best = mid ; } else l = mid+1 ; } pii myEdge = edge[best] ; dfs(myEdge.ff , best , 0) ; dfs(myEdge.ss, best, 1) ; debug("Found %d %d\n" , myEdge.ff, myEdge.ss) ; for(int i : grupo[0]) debug("%d " , i) ; debug("\n") ; for(int i : grupo[1]) debug("%d " , i ) ; debug("\n") ; for(int i : grupo[0]) toAsk[i] = 1 ; ll newTot = (ask(toAsk) - Prev) / (B-A) ; memset(allowed, false, sizeof allowed) ; for(int i : grupo[0]) { toAsk[i] = 0 ; allowed[i] = true ; } S = findSpecial( myEdge.ff , allowed , newTot ) ; for(int i : grupo[0]) allowed[i] = false ; for(int i : grupo[1]) allowed[i] = true ; T = findSpecial(myEdge.ss , allowed, rad - newTot- 1) ; answer(S,T) ; }

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

highway.cpp: In function 'int findSpecial(int, bool*, long long int)':
highway.cpp:72:22: warning: left operand of comma operator has no effect [-Wunused-value]
  debug("%d %lld\n" , s  ,curRad) ;
                      ^
highway.cpp:72:26: warning: right operand of comma operator has no effect [-Wunused-value]
  debug("%d %lld\n" , s  ,curRad) ;
                          ^~~~~~
highway.cpp:73:51: warning: left operand of comma operator has no effect [-Wunused-value]
  lp(i,0,m) debug("%d " , allowed[i] == true ? 1 : 0) ;
                                                   ^
highway.cpp:74:14: warning: statement has no effect [-Wunused-value]
  debug("\n") ;
              ^
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:8:12: warning: left operand of comma operator has no effect [-Wunused-value]
 #define ff first
            ^
highway.cpp:178:34: note: in expansion of macro 'ff'
   debug("Found %d %d\n" , myEdge.ff, myEdge.ss) ;
                                  ^~
highway.cpp:8:12: warning: right operand of comma operator has no effect [-Wunused-value]
 #define ff first
            ^
highway.cpp:178:34: note: in expansion of macro 'ff'
   debug("Found %d %d\n" , myEdge.ff, myEdge.ss) ;
                                  ^~
highway.cpp:180:40: warning: left operand of comma operator has no effect [-Wunused-value]
   for(int i : grupo[0]) debug("%d " ,  i) ;
                                        ^
highway.cpp:181:15: warning: statement has no effect [-Wunused-value]
   debug("\n") ;
               ^
highway.cpp:183:39: warning: left operand of comma operator has no effect [-Wunused-value]
   for(int i : grupo[1]) debug("%d " , i ) ;
                                       ^
highway.cpp:184:15: warning: statement has no effect [-Wunused-value]
   debug("\n") ;
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...