結果
問題 | No.359 門松行列 |
ユーザー | h_noson |
提出日時 | 2016-04-18 01:47:15 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,315 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 72,196 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 12:54:31 |
合計ジャッジ時間 | 1,223 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 typedef long long ll; vector<pair<int,int>> integrate(vector<pair<int,int>> a, vector<pair<int,int>> b) { vector<pair<int,int>> ret; int ia, ib; ia = ib = 0; while (ia < a.size() && ib < b.size()) { if (a[ia].second < b[ib].first) { ia++; continue; } else if (b[ib].second < a[ia].first) { ib++; continue; } ret.push_back(make_pair(max(a[ia].first,b[ib].first),min(a[ia].second,b[ib].second))); if (a[ia].second <= b[ib].second) ia++; else ib++; } return ret; } vector<pair<int,int>> solve(int l, bool center, int a, int b) { vector<pair<int,int>> ret; if (center) { if (a == 0 || b == 0) { int x = max(a,b); if (l / 2 >= x) { ret.push_back(make_pair(1,x-1)); if ((l+1)/2-1 > x) ret.push_back(make_pair(l/2+1,l-x-1)); ret.push_back(make_pair(l-x+1,l-1)); } else { ret.push_back(make_pair(1,l-x-1)); if ((l-1)/2+1 < x) ret.push_back(make_pair(l-x+1,(l-1)/2)); if (x < l-1) ret.push_back(make_pair(x+1,l-1)); } } else { if (min(a,b) > 1) ret.push_back(make_pair(1,min({a-1,b-1,l-1}))); if (max(a,b) < l-1) ret.push_back(make_pair(max(a,b)+1,l-1)); } } else { if (a == 0) { if (l / 2 >= b) { ret.push_back(make_pair(1,b-1)); if ((l+1)/2-1 > b) ret.push_back(make_pair(b+1,(l-1)/2)); if (b > 1) ret.push_back(make_pair(l-b+1,l-1)); } else { if (b < l-1) ret.push_back(make_pair(1,l-b-1)); if (l/2+1 < b) ret.push_back(make_pair(l/2+1,b-1)); if (b < l-1) ret.push_back(make_pair(b+1,l-1)); } } else if (b == 0) { if (l/2+1 < a) { if (l % 2 == 0) { ret.push_back(make_pair(1,l/2-1)); ret.push_back(make_pair(l/2+1,min(l-1,a-1))); } else ret.push_back(make_pair(1,min(l-1,a-1))); } else if ((l+1)/2-1 > a) { if (l % 2 == 0) { ret.push_back(make_pair(a+1,l/2-1)); ret.push_back(make_pair(l/2+1,l-a-1)); } else ret.push_back(make_pair(a+1,l-a-1)); } } else { if (a < b) { if (b - a > 1 && l-1 > a) ret.push_back(make_pair(a+1,min(b-1,l-1))); if (b < l-1) ret.push_back(make_pair(b+1,l-1)); } else { if (b > 1) ret.push_back(make_pair(1,min(b-1,l-1))); if (a - b > 1 && l-1 > b) ret.push_back(make_pair(b+1,min(a-1,l-1))); } } } return ret; } int main() { int t, k; cin >> t; rep (k,t) { int i, j, l, cnt, ans; int a[3][3]; vector<pair<int,int>> range; cin >> l; rep (i,3) rep (j,3) cin >> a[i][j]; range.push_back(make_pair(1,l-1)); rep (i,3) { rep (j,3) { if (a[i][j] == 0) { if (i == 1) range = integrate(range,solve(l,true,a[0][j],a[2][j])); else range = integrate(range,solve(l,false,a[1][j],max(a[0][j],a[2][j]))); if (j == 1) range = integrate(range,solve(l,true,a[i][0],a[i][2])); else range = integrate(range,solve(l,false,a[i][1],max(a[i][0],a[i][2]))); if (i == j) { if (i == 1) range = integrate(range,solve(l,true,a[0][0],a[2][2])); else range = integrate(range,solve(l,false,a[1][1],max(a[0][0],a[2][2]))); } if (i == 2-j) { if (i == 1) range = integrate(range,solve(l,true,a[0][2],a[2][0])); else range = integrate(range,solve(l,false,a[1][1],max(a[0][2],a[2][0]))); } auto tmp = range; range.clear(); for (auto p = tmp.rbegin(); p != tmp.rend(); p++) range.push_back(make_pair(l-p->second,l-p->first)); } } } ans = 0; for (auto p : range) ans += p.second - p.first + 1; cout << ans << endl; } return 0; }