結果
問題 | No.1346 Rectangle |
ユーザー |
|
提出日時 | 2021-02-03 18:50:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 2,484 ms |
コンパイル使用メモリ | 192,412 KB |
最終ジャッジ日時 | 2025-01-18 11:07:18 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int black(int x, int y) { return __builtin_popcountll(x & y); } int white(int x, int y, int n) { x = ~x; y = ~y; int mask = (1<<n) - 1; return __builtin_popcountll(x & y & mask); } bool go(vector<int> &masks, int pos, int n) { if (pos == masks.size()) { for (int i = 0; i < masks.size(); i++) { for (int j = 0; j < i; j++) { if (black(masks[i], masks[j]) >= 2 || white(masks[i], masks[j], n) >= 2) return false; } } return true; } for (int i = 0; i < 1<<n; i++) { masks[pos] = i; if (go(masks, pos+1, n)) return true; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; /* // 実験コード for (int i = 1; i < 8; i++) { cout << i << " "; vector<int> masks(i); if (go(masks, 0, n)) cout << "ok" << endl; else cout << "ng" << endl; } */ if (n <= 2) cout << "INF" << endl; else if (n <= 4) cout << 6 << endl; else if (n <= 6) cout << 4 << endl; else cout << 2 << endl; return 0; }