제출 #1140481

#제출 시각아이디문제언어결과실행 시간메모리
1140481tsengangArranging Shoes (IOI19_shoes)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define pb push_back #define ertunt return #define vodka void #include "shoes.h" long long count_swaps(vector<int> s) { ll n = s.size()/2; if(n == 1){ if(s[0] < 0)ertunt 0; else ertunt 1; } vector<ll> adj[n+4][2]; map<ll,ll>m; for(ll i = 0; i < s.size(); i++){ m[abs(s[i])] = 1; if(s[i] < 0){ adj[abs(s[i])][0].pb(i); } else adj[s[i]][1].pb(i); } ll cnt = 0; ll k = -1; ll ans = 0; for(auto x : m){ cnt++; k = x; for(ll i = 0; i < adj[x][0]; i++){ if(adj[x][0][i] > adj[x][1][i]){ ans+=adj[x][0][i] - adj[x][1][i] - 1; } else{ ans+=adj[x][1][i] - adj[x][0][i] - 2; } } } if(cnt == 0){ ertunt ans; } }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:31:13: error: cannot convert 'std::pair<const long long int, long long int>' to 'long long int' in assignment
   31 |         k = x;
      |             ^
      |             |
      |             std::pair<const long long int, long long int>
shoes.cpp:32:30: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   32 |         for(ll i = 0; i < adj[x][0]; i++){
      |                              ^
shoes.cpp:33:19: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   33 |             if(adj[x][0][i] > adj[x][1][i]){
      |                   ^
shoes.cpp:33:34: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   33 |             if(adj[x][0][i] > adj[x][1][i]){
      |                                  ^
shoes.cpp:34:25: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   34 |                 ans+=adj[x][0][i] - adj[x][1][i] - 1;
      |                         ^
shoes.cpp:34:40: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   34 |                 ans+=adj[x][0][i] - adj[x][1][i] - 1;
      |                                        ^
shoes.cpp:37:25: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   37 |                 ans+=adj[x][1][i] - adj[x][0][i] - 2;
      |                         ^
shoes.cpp:37:40: error: no match for 'operator[]' (operand types are 'std::vector<long long int> [(n + 4)][2]' and 'std::pair<const long long int, long long int>')
   37 |                 ans+=adj[x][1][i] - adj[x][0][i] - 2;
      |                                        ^
shoes.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^