Submission #2656793

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


int N,K;
vector<vector<ll>> imos;

inline ll sub(int left, int top, int right, int bottom){
    // [left, right], [top, bottom]
    ll a = imos[1+right][1+bottom] - imos[1+right][1+top-1]
         - imos[1+left-1][1+bottom] + imos[1+left-1][1+top-1];
    // printf("sub(%d,%d,%d,%d) = %lld\n", left,top,right,bottom, a);
    return a;
}
ll imos_count1(int left, int top){
    left %= K*2; top %= K*2;
    if (left < K) {
        if (top < K) {
            return sub(left,top, left+K-1,top+K-1);
        } else {
            // K <= top
            return sub(left,top, left+K-1,  K*2-1)
                 + sub(left,  0, left+K-1,top-K-1);
        }
    } else {
        // K <= left
        if (top < K) {
            return sub(left,top,    K*2-1,top+K-1)
                 + sub(   0,top, left-K-1,top+K-1);
        } else {
            return sub(left,top,    K*2-1,  K*2-1)
                 + sub(   0,top, left-K-1,  K*2-1)
                 + sub(left,  0,    K*2-1,top-K-1)
                 + sub(   0,  0, left-K-1,top-K-1);
        }
    }
}
ll imos_count(int left, int top){
    return imos_count1(left,top)
         + imos_count1(left+K, top+K);
}


ll solve(vi& x,vi& y,vi& c){
    // vi rx(N), ry(N);
    imos.assign(K*2+1, vector<ll>(K*2+1, 0));
    // vvi imos(K*2+1, vi(K*2+1, 0));

    rep(i,N){ //1e5
        int xi = x[i] + (c[i] ? K : 0);
        int yi = y[i]; // (c[i] ? K : 0);
        int rx_i = xi%(K*2); // [0..2K)
        int ry_i = yi%(K*2); // [0..2K)
        ++imos[1+rx_i][1+ry_i];
    }
    rep(r,K*2+1) {
        rep(c,K*2) {
            imos[r][c+1] += imos[r][c];
        }
    }
    rep(c,K*2+1) {
        rep(r,K*2) {
            imos[r+1][c] += imos[r][c];
        }
    }
// #ifdef DEBUG
//     rep(r,K*2+1) {
//         cerr << imos[r] << endl;
//     }
// #endif
    ll best = 0LL;
    rep(left, K*2) {
        rep(top, K*2) {
            ll cnt = imos_count(left, top);
            // printf("(%d,%d)->%lld\n", left,top, cnt);
            best = max(best, cnt);
        }
    }
    return best;

    // 2000 x 2000全シフト試すと 4e6; 4e11で死ぬる

}

int main() {
    // int N, K;
    cin >> N >> K; // 1-1e5, 1-1000
    vi x(N), y(N), c(N); // 0-1e9 0-1e9 B=0,W=1
    rep(i,N) {
        char ch;
        cin >> x[i] >> y[i] >> ch;
        c[i] = (ch == 'W') ? 1 : 0;
    }
    cout << solve(x,y,c) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Checker
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3545 Byte
Status
Exec Time 256 ms
Memory 32896 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_000.txt, 0_001.txt, 0_002.txt
All 500 / 500 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt
Case Name Status Exec Time Memory
0_000.txt 1 ms 256 KB
0_001.txt 167 ms 31616 KB
0_002.txt 1 ms 256 KB
1_003.txt 166 ms 31616 KB
1_004.txt 1 ms 256 KB
1_005.txt 1 ms 256 KB
1_006.txt 1 ms 256 KB
1_007.txt 2 ms 512 KB
1_008.txt 167 ms 31616 KB
1_009.txt 2 ms 256 KB
1_010.txt 2 ms 256 KB
1_011.txt 2 ms 256 KB
1_012.txt 3 ms 640 KB
1_013.txt 168 ms 31616 KB
1_014.txt 88 ms 1408 KB
1_015.txt 88 ms 1408 KB
1_016.txt 93 ms 1408 KB
1_017.txt 100 ms 1792 KB
1_018.txt 256 ms 32768 KB
1_019.txt 7 ms 640 KB
1_020.txt 7 ms 640 KB
1_021.txt 7 ms 640 KB
1_022.txt 7 ms 640 KB
1_023.txt 7 ms 640 KB
1_024.txt 7 ms 640 KB
1_025.txt 65 ms 1408 KB
1_026.txt 243 ms 32768 KB
1_027.txt 66 ms 1408 KB
1_028.txt 232 ms 32768 KB
1_029.txt 66 ms 1408 KB
1_030.txt 231 ms 32896 KB