# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1062436 | seoul_korea | Naval battle (CEOI24_battle) | C++17 | 1454 ms | 51192 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Goten2308
#include<bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using ii = pair <int, int>;
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define BIT(x, y) ((x >> y) & 1)
#define MASK(x) (1 << x)
#define MOD 1000000007
#define MULTI_TEST1
#define __GOTEN_WILL_BE_BETTER__ signed main()
template <class T> bool maximize(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template <class T> bool minimize(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template <class T> void add(T& a, T b) { a += b; if(a >= MOD) a -= MOD; }
template <class T> void sub(T& a, T b) { a -= b; if(a < 0) a += MOD; }
const int maxN = 100100;
int n;
struct Event{
int fr, to, at;
Event() {
fr = 0, to = 0, at = 0;
}
Event(int _fr, int _to, int _at) {
fr = _fr;
to = _to;
at = _at;
}
};
bool cmp(Event a, Event b) {
return a.at < b.at;
}
struct Board{
int x, y;
char type;
} a[maxN];
vector<int> store[5];
namespace Subtask5 {
bool Check() {
return n <= 5000;
}
map<ii, bool> isDelTime;
// int n;
int enc(char x) {
if(x == 'S') return 0;
if(x == 'N') return 1;
if(x == 'E') return 2;
if(x == 'W') return 3;
}
int calcTime(Board a, Board b) {
if(enc(a.type) > enc(b.type)) swap(a, b);
if(enc(a.type) == 0) {
if(enc(b.type) == 1) {
if(a.x > b.x || a.y != b.y || (a.x + b.x & 1)) return -1;
return (a.x + b.x >> 1) - a.x;
}
if(enc(b.type) == 2) {
if(b.x - a.x == a.y - b.y && a.y - b.y >= 0) return a.y - b.y;
return -1;
}
if(enc(b.type) == 3) {
if(b.x - a.x == b.y - a.y && b.y - a.y >= 0) return b.y - a.y;
return -1;
}
}
if(enc(a.type) == 1) {
if(enc(b.type) == 2) {
if(a.x - b.x == a.y - b.y && a.y - b.y >= 0) return a.y - b.y;
return -1;
}
if(enc(b.type) == 3) {
if(a.x - b.x == b.y - a.y && b.y - a.y >= 0) return b.y - a.y;
return -1;
}
}
if(enc(a.type) == 2) {
if(enc(b.type) == 3) {
if((a.y + b.y & 1) || a.x != b.x || a.y > b.y) return -1;
return (a.y + b.y >> 1) - a.y;
}
}
}
void solve() {
// cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].y >> a[i].x >> a[i].type;
store[enc(a[i].type)].pb(i);
}
vector<Event> timeline;
for(int i = 1; i <= n; i++) {
for(int nxt = 0; nxt <= 3; nxt++) {
if(nxt == enc(a[i].type)) continue;
for(auto j : store[nxt]) {
if(i > j) continue;
int k = calcTime(a[i], a[j]);
if(k == -1) continue;
timeline.push_back(Event(i, j, k));
}
}
}
sort(all(timeline), cmp);
vector<bool> isAlive(n + 1, 1);
Event last = Event();
for(auto sukien : timeline) {
if(isAlive[sukien.fr] && isAlive[sukien.to] || isDelTime.find(mp(sukien.fr, sukien.at)) != isDelTime.end() || isDelTime.find(mp(sukien.to, sukien.at)) != isDelTime.end()) {
isAlive[sukien.fr] = 0;
isAlive[sukien.to] = 0;
// isDelTime[sukien.fr][sukien.at] = 1;
isDelTime[mp(sukien.fr,sukien.at)] = 1;
isDelTime[mp(sukien.to,sukien.at)] = 1;
}
// last = sukien;
// cout << sukien.fr << ' ' << sukien.to << ' ' << sukien.at << endl;
}
for(int i = 1; i <= n; i++) if(isAlive[i]) cout << i << endl;
}
}
namespace Subtask6 {
void solve() {
for(int i = 1; i <= n; i++) cin >> a[i].y >> a[i].x >> a[i].type;
vector<ii> canDie;
for(int i = 1; i <= n; i++) {
canDie.push_back(mp(a[i].x + a[i].y, i));
// cout << canDie[0].fi;
}
sort(all(canDie));
vector<bool> isAlive(n + 1, true);
for(int timeTry = 0; timeTry < canDie.size();) {
vector<ii> timeDie;
int i = timeTry;
for(; i < canDie.size(); i++) {
if(canDie[i].fi != canDie[timeTry].fi) break;
timeDie.push_back(mp(a[canDie[i].se].y, canDie[i].se));
}
timeTry = i;
sort(all(timeDie));
stack<int> st;
for(auto x : timeDie) {
// cout << x.fi << ' ' << x.se << endl;
if(a[x.se].type == 'S') {
if(st.size()) {
isAlive[x.se] = isAlive[st.top()] = 0;
st.pop();
}
}else st.push(x.se);
}
}
for(int i = 1; i <= n; i++) if(isAlive[i]) cout << i << endl;
}
}
void solve() {
cin >> n;
if(Subtask5::Check()) Subtask5::solve();
else Subtask6::solve();
}
__GOTEN_WILL_BE_BETTER__ {
#define task ""
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
if(fopen("task.inp", "r")){
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
cin.tie(0)->ios_base::sync_with_stdio(0);
int nTest = 1;
#ifdef MULTI_TEST
cin >> nTest;
#endif
while(nTest--) {
solve();
}
cout << endl;
return 0;
}
Compilation message (stderr)
# | 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... |