提出 #48290758
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mx = 1e3 + 5;
int n, q;
int a[mx][mx];
ll g(int x, int y){
if(x<=n && y<=n)
return a[x][y];
int xx = x / n, xm = x % n;
int yy = y / n, ym = y % n;
ll ans = 0;
ans += 1LL * g(n, n) * xx * yy;
ans += 1LL * g(xm, n) * yy;
ans += 1LL * g(n, ym) * xx;
ans += 1LL * g(xm, ym);
return ans;
}
ll f(int x, int y, int xx, int yy){
return g(xx, yy) - g(x, yy) - g(xx, y) + g(x, y);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> q;
char ch;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j){
cin >> ch;
a[i][j] = ch == 'B';
a[i][j] += a[i-1][j];
a[i][j] += a[i][j-1];
a[i][j] -= a[i-1][j-1];
}
int x, y, xx, yy;
while(q--){
cin >> x >> y >> xx >> yy;
cout << f(x, y, xx+1, yy+1) << "\n";
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Tile Pattern |
| ユーザ | Turin |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 450 |
| コード長 | 1028 Byte |
| 結果 | AC |
| 実行時間 | 102 ms |
| メモリ | 7916 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 450 / 450 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_corner_00.txt, 01_corner_01.txt, 01_corner_02.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 03_max_00.txt, 03_max_01.txt, 04_n_small_00.txt, 04_n_small_01.txt, 04_n_small_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3432 KiB |
| 00_sample_01.txt | AC | 1 ms | 3520 KiB |
| 01_corner_00.txt | AC | 67 ms | 4092 KiB |
| 01_corner_01.txt | AC | 2 ms | 3568 KiB |
| 01_corner_02.txt | AC | 1 ms | 3480 KiB |
| 02_random_00.txt | AC | 59 ms | 4952 KiB |
| 02_random_01.txt | AC | 38 ms | 5016 KiB |
| 02_random_02.txt | AC | 34 ms | 4124 KiB |
| 02_random_03.txt | AC | 21 ms | 4164 KiB |
| 02_random_04.txt | AC | 33 ms | 5980 KiB |
| 02_random_05.txt | AC | 66 ms | 5788 KiB |
| 03_max_00.txt | AC | 98 ms | 7916 KiB |
| 03_max_01.txt | AC | 102 ms | 7892 KiB |
| 04_n_small_00.txt | AC | 44 ms | 3440 KiB |
| 04_n_small_01.txt | AC | 41 ms | 3500 KiB |
| 04_n_small_02.txt | AC | 40 ms | 3524 KiB |