답안 #831712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831712 2023-08-20T12:35:18 Z finn__ 고대 책들 (IOI17_books) C++17
컴파일 오류
0 ms 0 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
using L = long long;
 
long long minimum_walk(std::vector<int> p, int s)
{
    size_t const n = p.size();
    L ans = 0;
    for (int i = 0; i < n; ++i)
        ans += abs(i - p[i]);
 
    int first_non_id = 0, last_non_id = n - 1;
    while (first_non_id < n && p[first_non_id] == first_non_id)
        ++first_non_id;
    while (last_non_id >= 0 && p[last_non_id] == last_non_id)
        --last_non_id;
  
  first_non_id = min(first_non_id, s);
  last_non_id = max(last_non_id, s);
 
    int component_end = 0;
    for (int i = first_non_id; i <= last_non_id; ++i)
    {
        component_end = max(component_end, max(i, p[i]));
        if (component_end == i)
            ans += 2;
    }
 
    return ans - 2;
}

Compilation message

books.cpp:19:2: error: extended character   is not valid in an identifier
   19 |   first_non_id = min(first_non_id, s);
      |  ^
books.cpp:20:2: error: extended character   is not valid in an identifier
   20 |   last_non_id = max(last_non_id, s);
      |  ^
books.cpp:26:2: error: extended character   is not valid in an identifier
   26 |         if (component_end == i)
      |  ^
books.cpp:26:5: error: extended character   is not valid in an identifier
   26 |         if (component_end == i)
      |    ^
books.cpp:26:8: error: extended character   is not valid in an identifier
   26 |         if (component_end == i)
      |      ^
books.cpp:26:11: error: extended character   is not valid in an identifier
   26 |         if (component_end == i)
      |        ^
books.cpp:30:2: error: extended character   is not valid in an identifier
   30 |     return ans - 2;
      |  ^
books.cpp:30:5: error: extended character   is not valid in an identifier
   30 |     return ans - 2;
      |    ^
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < n; ++i)
      |                     ~~^~~
books.cpp:14:25: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   14 |     while (first_non_id < n && p[first_non_id] == first_non_id)
      |            ~~~~~~~~~~~~~^~~
books.cpp:19:2: error: '\U000000a0first_non_id' was not declared in this scope; did you mean 'first_non_id'?
   19 |   first_non_id = min(first_non_id, s);
      |  ^~~~~~~~~~~~~
      |  first_non_id
books.cpp:20:2: error: '\U000000a0last_non_id' was not declared in this scope; did you mean 'last_non_id'?
   20 |   last_non_id = max(last_non_id, s);
      |  ^~~~~~~~~~~~
      |  last_non_id
books.cpp:26:2: error: '\U000000a0' was not declared in this scope
   26 |         if (component_end == i)
      |  ^
books.cpp:30:2: error: '\U000000a0' was not declared in this scope
   30 |     return ans - 2;
      |  ^
books.cpp:31:1: warning: no return statement in function returning non-void [-Wreturn-type]
   31 | }
      | ^