제출 #1080570

#제출 시각아이디문제언어결과실행 시간메모리
1080570raphaelpNaval battle (CEOI24_battle)C++14
30 / 100
162 ms16352 KiB
#include <bits/stdc++.h> using namespace std; struct ship { int x, y; char type; int dirx, diry, i; }; istream &operator>>(istream &is, ship &s) { is >> s.x >> s.y >> s.type; if (s.type == 'E') s.dirx = 1, s.diry = 0; if (s.type == 'W') s.dirx = -1, s.diry = 0; if (s.type == 'S') s.dirx = 0, s.diry = 1; if (s.type == 'N') s.dirx = 0, s.diry = -1; return is; } bool operator<(ship a, ship b) { if (a.x + a.y == b.x + b.y) return a.x < b.x; return a.x + a.y < b.x + b.y; } void colide(int i, int j, vector<ship> &ships, vector<vector<int>> &colisions) { ship a = ships[i], b = ships[j]; if (a.type == b.type) return; if (a.dirx == 0 && b.dirx == 0 && ((a.y < b.y && a.diry == 1) || (a.y > b.y && a.diry == -1)) && a.x == b.x) colisions.push_back({abs(a.y - b.y) / 2, i, j}); if (a.diry == 0 && b.diry == 0 && ((a.x < b.x && a.dirx == 1) || (a.x > b.x && a.dirx == -1)) && a.y == b.y) colisions.push_back({abs(a.x - b.x) / 2, i, j}); if (a.diry == 0) swap(a, b); if (((a.y < b.y && a.diry == 1) || (a.y > b.y && a.diry == -1)) && ((b.x < a.x && b.dirx == 1) || (b.x > a.x && b.dirx == -1)) && abs(a.x - b.x) == abs(a.y - b.y)) colisions.push_back({abs(a.x - b.x), i, j}); } int find(int x, vector<int> &r) { if (x == r.size()) return x; return (r[x] == x) ? x : r[x] = find(r[x], r); } int main() { auto comp = [&](ship a, ship b) { return a.y < b.y; }; int N; cin >> N; vector<ship> ships(N); vector<ship> E, S; for (int i = 0; i < N; i++) { cin >> ships[i]; ships[i].i = i; if (ships[i].type == 'E') { E.push_back(ships[i]); } else S.push_back(ships[i]); } sort(S.begin(), S.end()); sort(E.begin(), E.end(), comp); vector<int> alive(N, 1); vector<int> r(S.size()); for (int i = 0; i < S.size(); i++) { r[i] = i; } for (int i = 0; i < E.size(); i++) { int x = lower_bound(S.begin(), S.end(), E[i]) - S.begin(); if (x == S.size()) continue; x = find(x, r); if (x == S.size()) continue; if (S[x].x + S[x].y == E[i].x + E[i].y) { alive[S[x].i] = 0; alive[E[i].i] = 0; r[x] = x + 1; } } for (int i = 0; i < N; i++) if (alive[i]) cout << i + 1 << '\n'; }

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

Main.cpp: In function 'int find(int, std::vector<int>&)':
Main.cpp:44:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     if (x == r.size())
      |         ~~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int i = 0; i < S.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 0; i < E.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp:80:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         if (x == S.size())
      |             ~~^~~~~~~~~~~
Main.cpp:83:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         if (x == S.size())
      |             ~~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...