Submission #28811515
Source Code Expand
#include <atcoder/all>
using namespace atcoder;
// using mint = modint998244353;
using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
// using P = pair<int,int>;
using vint = vector<int>;
using vll = vector<ll>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }
template<typename T>
void print(vector<T> v) {
int n = v.size();
rep(i,n) {
if (i == 0) cout << v[i];
else cout << ' ' << v[i];
}
cout << endl;
}
void solve() {
int n;
cin >> n;
int n2 = 1ll<<n;
vector<P> spices(n2);
rep(i,n2-1) {
ll c;
cin >> c;
spices[i] = {c,i+1};
}
sort(all(spices));
vint base(n, 0);
ll ans = 0;
for (auto [cost, x] : spices) {
rep(i,n) if (x>>i&1) x ^= base[i];
if (x == 0) continue;
ans += cost;
int i = 0;
while (!(x>>i&1)) i++;
base[i] = x;
}
// print(base);
// rep(i,n) rep(j,n) if ((base[i]>>j&1) && i != j) base[i] ^= base[j];
// print(base);
cout << ans << endl;
}
int main() {
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Spices |
| User | goropikari |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1612 Byte |
| Status | AC |
| Exec Time | 42 ms |
| Memory | 4332 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 18 ms | 3516 KiB |
| 001.txt | AC | 37 ms | 4324 KiB |
| 002.txt | AC | 28 ms | 4184 KiB |
| 003.txt | AC | 28 ms | 4332 KiB |
| 004.txt | AC | 39 ms | 4164 KiB |
| 005.txt | AC | 35 ms | 4180 KiB |
| 006.txt | AC | 38 ms | 4160 KiB |
| 007.txt | AC | 42 ms | 4160 KiB |
| 008.txt | AC | 37 ms | 4104 KiB |
| 009.txt | AC | 34 ms | 4092 KiB |
| 010.txt | AC | 34 ms | 4092 KiB |
| 011.txt | AC | 37 ms | 4224 KiB |
| 012.txt | AC | 37 ms | 4236 KiB |
| 013.txt | AC | 36 ms | 4164 KiB |
| 014.txt | AC | 36 ms | 4232 KiB |
| 015.txt | AC | 35 ms | 4092 KiB |
| 016.txt | AC | 40 ms | 4160 KiB |
| 017.txt | AC | 39 ms | 4332 KiB |
| 018.txt | AC | 38 ms | 4164 KiB |
| 019.txt | AC | 32 ms | 4240 KiB |
| 020.txt | AC | 37 ms | 4324 KiB |
| 021.txt | AC | 33 ms | 4324 KiB |
| 022.txt | AC | 38 ms | 4244 KiB |
| 023.txt | AC | 38 ms | 4164 KiB |
| 024.txt | AC | 36 ms | 4184 KiB |
| 025.txt | AC | 2 ms | 3444 KiB |
| 026.txt | AC | 21 ms | 3712 KiB |
| 027.txt | AC | 3 ms | 3452 KiB |
| 028.txt | AC | 2 ms | 3620 KiB |
| 029.txt | AC | 27 ms | 3564 KiB |
| 030.txt | AC | 38 ms | 4236 KiB |
| 031.txt | AC | 37 ms | 4160 KiB |
| 032.txt | AC | 35 ms | 4160 KiB |
| 033.txt | AC | 33 ms | 4120 KiB |
| 034.txt | AC | 36 ms | 4164 KiB |
| example0.txt | AC | 2 ms | 3512 KiB |
| example1.txt | AC | 2 ms | 3516 KiB |