제출 #465360

#제출 시각아이디문제언어결과실행 시간메모리
465360dattranxxxArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms204 KiB
/* * Author : shora */ #include "shoes.h" #include <bits/stdc++.h> #define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl; using namespace std; using ll = long long; const int oo = 1e9; ll n; namespace task_1 { bool check(vector<int>& a) { return a.size() == 2; } ll solve(vector<int>& a) { return a[0] > 0; } } namespace task_2 { bool check(vector<int>& a) { return n <= 8; } map<vector<int>, ll> dis; ll solve(vector<int> a) { vector<int> fin(a.size()); for (int i = 0; i < n; ++i) fin[2*i] = -i-1, fin[2*i+1] = i+1; dis[a] = 0; queue<vector<int>> q; q.push(a); while (!q.empty()) { vector<int> cur = q.front(); q.pop(); if (cur == fin) return dis[cur]; int d = dis[cur]; for (int i = 1; i < cur.size(); ++i) { swap(cur[i], cur[i-1]); if (!dis.count(cur)) { dis[cur] = d + 1; q.push(cur); } swap(cur[i], cur[i-1]); } } return dis[fin]; } } namespace task_3 { bool check(vector<int>& a) { int x = a[0]; for (int i = 1; i < a.size(); ++i) if (a[i] != x && a[i] != -x) return 0; return 1; } ll solve(vector<int>& a) { ll res = 0; int c = 0; for (int i = 0; i < a.size(); ++i) { if (a[i] < 0) { res += i - c; c++; } } return res; } } namespace task_4 { bool check(vector<int>& a) { for (int i = 0; i < n; ++i) if (a[i] > 0 || a[i] != -a[i+n]) return 0; return 1; } ll solve(vector<int>& a) { return n * (n-1) / 2; } } long long count_swaps(std::vector<int> a) { n = a.size() / 2; if (task_1::check(a)) return task_1::solve(a); if (task_2::check(a)) return task_2::solve(a); if (task_3::check(a)) return task_3::solve(a); if (task_4::check(a)) return task_4::solve(a); return -1; }

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

shoes.cpp: In function 'll task_2::solve(std::vector<int>)':
shoes.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for (int i = 1; i < cur.size(); ++i) {
      |                    ~~^~~~~~~~~~~~
shoes.cpp: In function 'bool task_3::check(std::vector<int>&)':
shoes.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int i = 1; i < a.size(); ++i)
      |                   ~~^~~~~~~~~~
shoes.cpp: In function 'll task_3::solve(std::vector<int>&)':
shoes.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int i = 0; i < a.size(); ++i) {
      |                   ~~^~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...