結果
| 問題 |
No.861 ケーキカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-09 22:19:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 6,520 bytes |
| コンパイル時間 | 1,670 ms |
| コンパイル使用メモリ | 173,544 KB |
| 実行使用メモリ | 17,084 KB |
| 最終ジャッジ日時 | 2024-07-19 12:17:23 |
| 合計ジャッジ時間 | 6,178 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
struct UnionFind
{
vector< int > data;
UnionFind(int sz)
{
data.assign(sz, -1);
}
bool unite(int x, int y)
{
x = find(x), y = find(y);
if(x == y) return(false);
if(data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
return(true);
}
int find(int k)
{
if(data[k] < 0) return(k);
return(data[k] = find(data[k]));
}
int size(int k)
{
return(-data[find(k)]);
}
};
int main(){
lint C[25];
cins(C, C + 25);
lint all = accumulate(C, C + 25, 0ll);
lint ans = 1e18;
int cnt = 0;
for(int i = 1; i < (1 << 25); i += 2){
UnionFind uf(25);
if((i >> 0) & (i >> 1) & 1){
uf.unite(0, 1);
}
if((i >> 1) & (i >> 2) & 1){
uf.unite(1, 2);
}
if((i >> 2) & (i >> 3) & 1){
uf.unite(2, 3);
}
if((i >> 3) & (i >> 4) & 1){
uf.unite(3, 4);
}
if((i >> 5) & (i >> 6) & 1){
uf.unite(5, 6);
}
if((i >> 6) & (i >> 7) & 1){
uf.unite(6, 7);
}
if((i >> 7) & (i >> 8) & 1){
uf.unite(7, 8);
}
if((i >> 8) & (i >> 9) & 1){
uf.unite(8, 9);
}
if((i >> 10) & (i >> 11) & 1){
uf.unite(10, 11);
}
if((i >> 11) & (i >> 12) & 1){
uf.unite(11, 12);
}
if((i >> 12) & (i >> 13) & 1){
uf.unite(12, 13);
}
if((i >> 13) & (i >> 14) & 1){
uf.unite(13, 14);
}
if((i >> 15) & (i >> 16) & 1){
uf.unite(15, 16);
}
if((i >> 16) & (i >> 17) & 1){
uf.unite(16, 17);
}
if((i >> 17) & (i >> 18) & 1){
uf.unite(17, 18);
}
if((i >> 18) & (i >> 19) & 1){
uf.unite(18, 19);
}
if((i >> 20) & (i >> 21) & 1){
uf.unite(20, 21);
}
if((i >> 21) & (i >> 22) & 1){
uf.unite(21, 22);
}
if((i >> 22) & (i >> 23) & 1){
uf.unite(22, 23);
}
if((i >> 23) & (i >> 24) & 1){
uf.unite(23, 24);
}
if((i >> 0) & (i >> 5) & 1){
uf.unite(0, 5);
}
if((i >> 5) & (i >> 10) & 1){
uf.unite(5, 10);
}
if((i >> 10) & (i >> 15) & 1){
uf.unite(10, 15);
}
if((i >> 15) & (i >> 20) & 1){
uf.unite(15, 20);
}
if((i >> 1) & (i >> 6) & 1){
uf.unite(1, 6);
}
if((i >> 6) & (i >> 11) & 1){
uf.unite(6, 11);
}
if((i >> 11) & (i >> 16) & 1){
uf.unite(11, 16);
}
if((i >> 16) & (i >> 21) & 1){
uf.unite(16, 21);
}
if((i >> 2) & (i >> 7) & 1){
uf.unite(2, 7);
}
if((i >> 7) & (i >> 12) & 1){
uf.unite(7, 12);
}
if((i >> 12) & (i >> 17) & 1){
uf.unite(12, 17);
}
if((i >> 17) & (i >> 22) & 1){
uf.unite(17, 22);
}
if((i >> 3) & (i >> 8) & 1){
uf.unite(3, 8);
}
if((i >> 8) & (i >> 13) & 1){
uf.unite(8, 13);
}
if((i >> 13) & (i >> 18) & 1){
uf.unite(13, 18);
}
if((i >> 18) & (i >> 23) & 1){
uf.unite(18, 23);
}
if((i >> 4) & (i >> 9) & 1){
uf.unite(4, 9);
}
if((i >> 9) & (i >> 14) & 1){
uf.unite(9, 14);
}
if((i >> 14) & (i >> 19) & 1){
uf.unite(14, 19);
}
if((i >> 19) & (i >> 24) & 1){
uf.unite(19, 24);
}
if(uf.size(0) == bitcount(i)){
lint sum = 0;
for(int j = 0; j < 25; j++){
sum += ((i >> j) & 1) * C[j];
}
ans = min(ans, abs(all - sum * 2));
cnt++;
}
}
cout << ans << endl;
cout << cnt << endl;
}