제출 #121971

#제출 시각아이디문제언어결과실행 시간메모리
121971nvmdava고대 책들 (IOI17_books)C++17
컴파일 에러
0 ms0 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; bool in[1000005]; vector<pair<int, int> > cyc, tmp; int mn, mx; long long res; void dfs(int i, vector<int>& p){ if(in[i]) return; in[i] = 1; mx = max(mx, i); mn = min(mn, i); dfs(p[i], p); } long long minimum_walk(std::vector<int> p, int s) { for(int i = 0; i < p.size(); i++){ res += abs(p[i] - i); if(in[i]) continue; mn = i; mx = i; dfs(i, p); if(mn != mx)tmp.push_back({mn , mx}); } if(tmp.empty()) return 0; sort(tmp.begin(), tmp.end()); mx = -1; for(auto& x : tmp){ if(mx < x.first){ if(!cyc.empty()){ res += 2 * (x.first - mx); } cyc.push_back(x); } mx = max(mx, x.second); } if(s < cyc[0].first) res += 2 * (cyc[0].first - s); if(s > cyc.back().second) res += 2 * (s - cyc.back().second); return res; } int main() { int n, s; scanf("%d %d", &n, &s); vector<int> p((unsigned) n); for(int i = 0; i < n; i++) 1 == scanf("%d", &p[(unsigned) i]); long long res = minimum_walk(p, s); printf("%lld\n", res); return 0; }

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

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++){
                 ~~^~~~~~~~~~
books.cpp: In function 'int main()':
books.cpp:51:5: warning: value computed is not used [-Wunused-value]
   1 == scanf("%d", &p[(unsigned) i]);
   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &s);
  ~~~~~^~~~~~~~~~~~~~~~~
/tmp/ccha50ZU.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccrnsuRk.o:books.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status