Submission #1106720

#TimeUsernameProblemLanguageResultExecution timeMemory
1106720Ntd123Naval battle (CEOI24_battle)C++14
0 / 100
3013 ms3144 KiB
#include <bits/stdc++.h>
#define PB push_back
#define F first
#define S second
#define ld long double
#define ll long long
#define pii pair <int, int>
#define MOD 1000000007
#define il (node * 2)
#define ir (il + 1)
#define mid (l + r)/2
#define all(x) x.begin(), x.end()
#define bit(x, i) ((x >> i) & 1)
#define maxn
#define Task "try_codeforce"

using namespace std;
const int N = 200005;
int n, mark[N];
char c[4] = {'N', 'S', 'E', 'W'};
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
struct cc{
    int x, y, z;
}a[N];
int get(char x){
    for (int i = 0; i < 4; i ++)
        if (c[i] == x)
            return i;
}
bool can_crash(int &w, cc p, cc q){
    if (dx[p.z] == dx[q.z] || dy[p.z] == dy[q.z]){
        w = max(abs(p.x-q.x), abs(p.y - q.y))/2;
    } else {
        w = max(abs(p.x-q.x), abs(p.y-q.y));
    }
    return p.x+dx[p.z]*w == q.x + dx[q.z]*w && p.y+dy[p.z]*w == p.y+dy[p.z]*w;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i ++){
        char z;
        int x, y;
        cin >> x >> y >> z;
        a[i] = {x, y, get(z)};
    }
    while (1){
        int x, y, z = MOD;
        for (int i = 1; i <= n; i ++)
        for (int j = i + 1; j <= n; j ++)
        if (!mark[i] && !mark[j]){
            int X = 0;
            if (can_crash(X, a[i], a[j])){
                if (z > X){
                    z = X;
                    x = i;
                    y = j;
                }
            }
        }
        if (z == MOD) break;
        mark[x] = mark[y] = 1;
    }
    for (int i = 1; i <= n; i ++)
    if (!mark[i])
    cout << i << '\n';
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'bool can_crash(int&, cc, cc)':
Main.cpp:37:62: warning: self-comparison always evaluates to true [-Wtautological-compare]
   37 |     return p.x+dx[p.z]*w == q.x + dx[q.z]*w && p.y+dy[p.z]*w == p.y+dy[p.z]*w;
      |                                                ~~~~~~~~~~~~~ ^~ ~~~~~~~~~~~~~
Main.cpp: In function 'int get(char)':
Main.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
   30 | }
      | ^
Main.cpp: In function 'int main()':
Main.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...