제출 #465370

#제출 시각아이디문제언어결과실행 시간메모리
465370aris12345678Arranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define X first
#define Y second

const int mxN = 100005;

bool check(pii s) {
    int n = int(s.size());
    for(int i = 1; i < n; i+=2) {
        if(s[i].X != -s[i-1].X)
            return false;
    }
    return true;
}

ll count_swaps(vector<int> s) {
    int n = int(s.size());
    if(n <= 16) {
        pii shoes;
        for(int i = 0; i < n; i++)
            shoes.push_back({s[i], i});
        sort(shoes.begin(), shoes.end());
        ll ans = LLONG_MAX;
        do {
            ll res = 0;
            if(!check(shoes)) continue;
            for(int i = 0; i < n; i++)
                res += abs(shoes[i].Y-i-1);
            ans = min(ans, res);
        } while(next_permutation(shoes.begin(), shoes.end()));
        return ans;
    } else {
        n /= 2;
        n--;
        return 1LL*n*(n+1)/2;
    }
    assert(true);
}

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

shoes.cpp: In function 'bool check(pii)':
shoes.cpp:13:19: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'size'
   13 |     int n = int(s.size());
      |                   ^~~~
shoes.cpp:15:13: error: no match for 'operator[]' (operand types are 'pii' {aka 'std::pair<int, int>'} and 'int')
   15 |         if(s[i].X != -s[i-1].X)
      |             ^
shoes.cpp:15:24: error: no match for 'operator[]' (operand types are 'pii' {aka 'std::pair<int, int>'} and 'int')
   15 |         if(s[i].X != -s[i-1].X)
      |                        ^
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:26:19: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'push_back'
   26 |             shoes.push_back({s[i], i});
      |                   ^~~~~~~~~
shoes.cpp:27:20: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'begin'
   27 |         sort(shoes.begin(), shoes.end());
      |                    ^~~~~
shoes.cpp:27:35: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'end'
   27 |         sort(shoes.begin(), shoes.end());
      |                                   ^~~
shoes.cpp:33:33: error: no match for 'operator[]' (operand types are 'pii' {aka 'std::pair<int, int>'} and 'int')
   33 |                 res += abs(shoes[i].Y-i-1);
      |                                 ^
shoes.cpp:35:40: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'begin'
   35 |         } while(next_permutation(shoes.begin(), shoes.end()));
      |                                        ^~~~~
shoes.cpp:35:55: error: 'pii' {aka 'struct std::pair<int, int>'} has no member named 'end'
   35 |         } while(next_permutation(shoes.begin(), shoes.end()));
      |                                                       ^~~