제출 #1086771

#제출 시각아이디문제언어결과실행 시간메모리
1086771quangminh412Arranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; /* John Watson https://codeforces.com/profile/quangminh98 Mua Code nhu mua Florentino !! */ #define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long ll count_swap(vector<int> s) { int n = s.size() / 2; bool sub3 = true, sub4 = true; int check = -1; for (int i = 0; i < s.size(); i++) { if (check == -1) check = abs(s[i]); else if (check != abs(s[i])) sub3 = false; if (i < n && s[i] > 0) sub4 = false; if (i >= n && s[i] < 0) sub4 = false; if (i < n && s[i] + s[i + n] != 0) sub4 = false; } if (n == 1) { // sub1 return (s[0] < 0 ? 0 : 1); } else if (sub3 == true) { int res1 = 0, res2 = 0; int cur1 = 0, cur2 = 0; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) { res1 += abs(s[i] - cur1 * 2); cur1++; } else { res2 += abs(s[i] - cur2 * 2 - 1); cur2++; } } return min(res1, res2); } else if (sub4 == true) { int res = 0; for (int i = n - 1; i >= 0; i--) res += i; return res; } int ans = 0; unordered_map<int, queue<int>> mark; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) mark[s[i]].push(i); else { int pos = mark[-s[i]].front(); mark[-s[i]].pop(); ans += abs(i - pos); } } cout << ans << '\n'; } #include <bits/stdc++.h> using namespace std; /* John Watson https://codeforces.com/profile/quangminh98 Mua Code nhu mua Florentino !! */ #define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long ll count_swap(vector<int> s) { int n = s.size() / 2; bool sub3 = true, sub4 = true; int check = -1; for (int i = 0; i < s.size(); i++) { if (check == -1) check = abs(s[i]); else if (check != abs(s[i])) sub3 = false; if (i < n && s[i] > 0) sub4 = false; if (i >= n && s[i] < 0) sub4 = false; if (i < n && s[i] + s[i + n] != 0) sub4 = false; } if (n == 1) { // sub1 return (s[0] < 0 ? 0 : 1); } else if (sub3 == true) { int res1 = 0, res2 = 0; int cur1 = 0, cur2 = 0; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) { res1 += abs(s[i] - cur1 * 2); cur1++; } else { res2 += abs(s[i] - cur2 * 2 - 1); cur2++; } } return min(res1, res2); } else if (sub4 == true) { int res = 0; for (int i = n - 1; i >= 0; i--) res += i; return res; } int ans = 0; unordered_map<int, queue<int>> mark; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) mark[s[i]].push(i); else { int pos = mark[-s[i]].front(); mark[-s[i]].pop(); ans += abs(i - pos); } } cout << ans << '\n'; }

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

shoes.cpp: In function 'long long int count_swap(std::vector<int>)':
shoes.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
shoes.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (int i = 0; i < s.size(); i++)
      |                   ~~^~~~~~~~~~
shoes.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
shoes.cpp: At global scope:
shoes.cpp:84:4: error: redefinition of 'long long int count_swap(std::vector<int>)'
   84 | ll count_swap(vector<int> s)
      |    ^~~~~~~~~~
shoes.cpp:14:4: note: 'long long int count_swap(std::vector<int>)' previously defined here
   14 | ll count_swap(vector<int> s)
      |    ^~~~~~~~~~
shoes.cpp: In function 'long long int count_swap(std::vector<int>)':
shoes.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
shoes.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for (int i = 0; i < s.size(); i++)
      |                   ~~^~~~~~~~~~
shoes.cpp:129:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
shoes.cpp: In function 'long long int count_swap(std::vector<int>)':
shoes.cpp:58:33: warning: control reaches end of non-void function [-Wreturn-type]
   58 |  unordered_map<int, queue<int>> mark;
      |                                 ^~~~
shoes.cpp: In function 'long long int count_swap(std::vector<int>)':
shoes.cpp:128:33: warning: control reaches end of non-void function [-Wreturn-type]
  128 |  unordered_map<int, queue<int>> mark;
      |                                 ^~~~