結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | mamekin |
提出日時 | 2018-03-25 11:36:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,610 ms / 2,500 ms |
コード長 | 3,551 bytes |
コンパイル時間 | 1,443 ms |
コンパイル使用メモリ | 121,300 KB |
実行使用メモリ | 441,856 KB |
最終ジャッジ日時 | 2024-06-25 05:38:24 |
合計ジャッジ時間 | 30,931 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 1,564 ms
441,724 KB |
testcase_11 | AC | 1,492 ms
441,728 KB |
testcase_12 | AC | 1,521 ms
441,652 KB |
testcase_13 | AC | 1,502 ms
441,728 KB |
testcase_14 | AC | 1,493 ms
441,728 KB |
testcase_15 | AC | 1,543 ms
441,732 KB |
testcase_16 | AC | 1,610 ms
441,728 KB |
testcase_17 | AC | 1,586 ms
441,728 KB |
testcase_18 | AC | 1,560 ms
441,856 KB |
testcase_19 | AC | 1,511 ms
441,728 KB |
testcase_20 | AC | 1,570 ms
441,600 KB |
testcase_21 | AC | 1,566 ms
441,600 KB |
testcase_22 | AC | 1,491 ms
441,728 KB |
testcase_23 | AC | 1,484 ms
441,728 KB |
testcase_24 | AC | 1,157 ms
441,600 KB |
testcase_25 | AC | 1,126 ms
441,728 KB |
testcase_26 | AC | 1,118 ms
441,472 KB |
testcase_27 | AC | 1,252 ms
441,600 KB |
testcase_28 | AC | 1,088 ms
441,600 KB |
testcase_29 | AC | 1,176 ms
441,472 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> using namespace std; template <class T> class cumulativeSum { private: int ny, nx; vector<vector<T> > sum; public: cumulativeSum(){} cumulativeSum(const vector<vector<T> >& a) { ny = a.size(); nx = a[0].size(); sum.assign(ny+1, vector<T>(nx+1, 0)); for(int i=0; i<ny; ++i){ for(int j=0; j<nx; ++j){ sum[i+1][j+1] = a[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j]; } } } T getSum(int y1, int x1, int y2, int x2) { y1 = max(y1, 0); x1 = max(x1, 0); y2 = min(y2, ny-1); x2 = min(x2, nx-1); if(y1 > y2 || x1 > x2) return 0; return sum[y2+1][x2+1] - sum[y1][x2+1] - sum[y2+1][x1] + sum[y1][x1]; } }; class TriangleSum { private: int n; cumulativeSum<long long> cs1, cs2; public: TriangleSum(const vector<vector<long long> >& v){ n = v.size(); vector<vector<long long> > a(n, vector<long long>(n, 0)); vector<vector<long long> > b(n, vector<long long>(n, 0)); for(int i=0; i<n; ++i){ for(int j=0; j<=i; ++j){ a[i][j] = v[i][j]; b[i][n-1-i+j] = v[i][j]; } } cs1 = cumulativeSum<long long>(a); a.clear(); cs2 = cumulativeSum<long long>(b); } long long getSum(int y, int x, int size){ long long ans = cs1.getSum(y, x, y+size-1, n-1); ans -= cs2.getSum(y, n-y+x, y+size-1, n-1); return ans; } }; void bfs(int n, const vector<int>& by, const vector<int>& bx, vector<vector<long long> >& dist) { static const int dy[] = {-1, -1, 0, 0, 1, 1}; static const int dx[] = {-1, 0, -1, 1, 0, 1}; dist.resize(n); for(int i=0; i<n; ++i) dist[i].assign(i+1, -1); int k = by.size(); queue<pair<int, int> > q; for(int i=0; i<k; ++i){ dist[by[i]][bx[i]] = 0; q.push(make_pair(by[i], bx[i])); } while(!q.empty()){ int y, x; tie(y, x) = q.front(); q.pop(); for(int i=0; i<6; ++i){ int y2 = y + dy[i]; int x2 = x + dx[i]; if(0 <= y2 && y2 < n && 0 <= x2 && x2 <= y2 && dist[y2][x2] == -1){ dist[y2][x2] = dist[y][x] + 1; q.push(make_pair(y2, x2)); } } } } int main() { int n, k; long long p; cin >> n >> k >> p; vector<int> by(k), bx(k); for(int i=0; i<k; ++i){ cin >> by[i] >> bx[i]; -- by[i]; -- bx[i]; } vector<vector<long long> > dist; bfs(n, by, bx, dist); TriangleSum ts(dist); long long ans = 0; for(int y=0; y<n; ++y){ for(int x=0; x<=y; ++x){ int left = 1; int right = n - y + 1; while(left < right){ int mid = (left + right) / 2; if(ts.getSum(y, x, mid) < p) left = mid + 1; else right = mid; } ans += (n - y + 1) - left; } } cout << ans << endl; return 0; }