이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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> l(S.size()), r(S.size());
for (int i = 0; i < S.size(); i++)
{
l[i] = i - 1;
r[i] = i + 1;
}
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;
if (alive[S[x].i] == 0)
x = r[x];
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;
if (l[x] != -1)
r[l[x]] = r[x];
if (r[x] != S.size())
l[r[x]] = l[x];
}
}
for (int i = 0; i < N; i++)
if (alive[i])
cout << i + 1 << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < S.size(); i++)
| ~~^~~~~~~~~~
Main.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < E.size(); i++)
| ~~^~~~~~~~~~
Main.cpp:75:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if (x == S.size())
| ~~^~~~~~~~~~~
Main.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | if (x == S.size())
| ~~^~~~~~~~~~~
Main.cpp:87:22: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | if (r[x] != S.size())
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |