제출 #139481

#제출 시각아이디문제언어결과실행 시간메모리
139481Kenzo_1114고대 책들 (IOI17_books)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; const int MAXN=1000010; int marc[MAXN],sub[MAXN],cur; long long int dist,resp; vector<int> grafo; void dfs(int v) { marc[v]=1; int viz=grafo[v]; if(marc[viz]==1) { dist+=abs(v-viz); return; } dist+=abs(v-viz); dfs(viz); } long long int minimum_walk(vector<int> p,int s) { vector<pair<int,int> > cycle; grafo=p; for(int i=p.size()-1;i>=0;i--) { if(i!=p[i]) break; p.pop_back(); } for(int i=0;i<p.size();i++) { int ini=i, fim=p[i]; while(i<fim) { i++; fim=max(fim,p[i]); } cycle.push_back(make_pair(ini,fim)); } for(int i=0;i<cycle.size();i++) { for(int j=cycle[i].first;j<=cycle[i].second;j++) { if(marc[j]==1) continue; dist=0; dfs(j); resp+=dist; } if(i!=cycle.size()-1) resp+=2*(cycle[i].first-cycle[i].second); } return resp; } /* int main () { int N,S,val; vector<int> P; scanf("%d %d",&N,&S); for(int i=0;i<N;i++) scanf("%d",&val), P.push_back(val); printf("%lld\n",minimum_walk(P,S)); } */

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

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();i++)
              ~^~~~~~~~~
books.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<cycle.size();i++)
              ~^~~~~~~~~~~~~
books.cpp:59:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i!=cycle.size()-1) resp+=2*(cycle[i].first-cycle[i].second);
      ~^~~~~~~~~~~~~~~~
#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...