Submission #59183695


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define inf 0x3f3f3f3f
#define pi pair<long long int,long long int>
#define gcd(x,y) __gcd( x, y)
#define ALL(x) x.begin(),x.end()
#define pll pair<long long,long long>
#define debug(x) cerr<<#x<<':'<<x<<endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define inf 0x3f3f3f3f
#define pi pair<long long int,long long int>
#define gcd(x,y) __gcd( x, y)
#define ALL(x) x.begin(),x.end()
#define pll pair<long long,long long>
#define debug(x) cerr<<#x<<':'<<x<<endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INTMAX 2147483647
#define INT_MAX LONG_LONG_MAX
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set_ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset_ll;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

ll countSafeSquares(ll n, vector<pll>& queens) {
    if(queens.empty()) return n * n;
    set<ll> rows, cols, d1, d2; 
    for(auto [r, c] : queens) {
        rows.insert(r);
        cols.insert(c);
        d1.insert(r + c);
        d2.insert(r - c);
    }
    ll attacked = 0;
    ll row_attacks = rows.size() * n, col_attacks = cols.size() * n;
    attacked = row_attacks + col_attacks - (rows.size() * cols.size());
    for(ll sum : d1) {
        ll from = max(0LL, sum - (n-1));
        ll to = min(n-1, sum); 
        ll len = to - from + 1;
        if(len > 0) {
            ll new_attacks = len;
            for(ll r = from; r <= to; r++) {
                ll c = sum - r;
                if(rows.count(r) || cols.count(c)) new_attacks--;
            }
            attacked += new_attacks;
        }
    }
    for(ll diff : d2) {
        ll from = max(0LL, diff);
        ll to = min(n-1, n-1 + diff);
        ll len = to - from + 1;
        if(len > 0) {
            ll new_attacks = len;
            for(ll r = from; r <= to; r++) {
                ll c = r - diff;
                if(rows.count(r) || cols.count(c) || d1.count(r + c)) new_attacks--;
            }
            attacked += new_attacks;
        }
    }
    return n * n - attacked;
}

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<pll> queens;
    rep(i, 0, q) {
        ll r, c;
        cin >> r >> c;
        r--; c--;
        queens.pb({r, c});
    }
    cout << countSafeSquares(n, queens) << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tc = 1; //cin >> tc;
    rep(t, 0, tc) {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task F - Avoid Queen Attack
User Jxsh28
Language C++ 17 (gcc 12.2)
Score 0
Code Size 3097 Byte
Status TLE
Exec Time 4414 ms
Memory 3688 KB

Compile Error

Main.cpp:25: warning: "INT_MAX" redefined
   25 | #define INT_MAX LONG_LONG_MAX
      | 
In file included from /usr/include/c++/12/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:39,
                 from Main.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/12/include/limits.h:120: note: this is the location of the previous definition
  120 | #define INT_MAX __INT_MAX__
      | 

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 550
Status
AC × 3
AC × 22
TLE × 21
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3544 KB
00_sample_01.txt AC 3157 ms 3516 KB
00_sample_02.txt AC 1 ms 3424 KB
01_random_03.txt AC 1 ms 3492 KB
01_random_04.txt AC 1 ms 3528 KB
01_random_05.txt AC 9 ms 3492 KB
01_random_06.txt AC 55 ms 3668 KB
01_random_07.txt AC 2416 ms 3688 KB
01_random_08.txt TLE 4414 ms 3488 KB
01_random_09.txt TLE 4414 ms 3420 KB
01_random_10.txt TLE 4414 ms 3560 KB
01_random_11.txt AC 1 ms 3452 KB
01_random_12.txt AC 1 ms 3452 KB
01_random_13.txt AC 7 ms 3596 KB
01_random_14.txt AC 1 ms 3492 KB
01_random_15.txt AC 564 ms 3684 KB
01_random_16.txt TLE 4414 ms 3412 KB
01_random_17.txt TLE 4414 ms 3484 KB
01_random_18.txt TLE 4414 ms 3432 KB
01_random_19.txt AC 1 ms 3472 KB
01_random_20.txt AC 1 ms 3480 KB
01_random_21.txt AC 1 ms 3548 KB
01_random_22.txt AC 1 ms 3384 KB
01_random_23.txt AC 1 ms 3468 KB
01_random_24.txt AC 1 ms 3524 KB
01_random_25.txt AC 1 ms 3488 KB
01_random_26.txt AC 1 ms 3444 KB
01_random_27.txt TLE 4414 ms 3516 KB
01_random_28.txt TLE 4414 ms 3368 KB
01_random_29.txt TLE 4414 ms 3348 KB
01_random_30.txt TLE 4414 ms 3372 KB
01_random_31.txt TLE 4414 ms 3448 KB
01_random_32.txt TLE 4414 ms 3520 KB
01_random_33.txt TLE 4414 ms 3372 KB
01_random_34.txt TLE 4414 ms 3448 KB
01_random_35.txt TLE 4414 ms 3512 KB
01_random_36.txt TLE 4414 ms 3444 KB
01_random_37.txt TLE 4414 ms 3356 KB
01_random_38.txt TLE 4414 ms 3444 KB
01_random_39.txt TLE 4414 ms 3244 KB
01_random_40.txt TLE 4414 ms 3372 KB
01_random_41.txt TLE 4414 ms 3384 KB
01_random_42.txt AC 39 ms 3636 KB


2025-03-05 (Wed)
12:24:50 +00:00