# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
727415 | model_code | Council (JOI23_council) | C++17 | 1373 ms | 104344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <array>
#include <bitset>
#include <iostream>
#include <vector>
using namespace std;
constexpr int N_MAX = 3e5, M_MAX = 20;
int popcnt(int x) { return bitset<32>(x).count(); }
int read() {
int x;
scanf("%d", &x);
return x;
}
int A[N_MAX], agree[M_MAX], sum[1 << M_MAX][M_MAX], mn[1 << M_MAX][2];
int main() {
const int N = read(), M = read();
// å…¥åŠ›ãƒ»å„æ¡ˆã«ä½•票ã‚ã‚‹ã‹æ•°ãˆã‚‹
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
const int x = read();
A[i] |= x << j;
agree[j] += x;
}
}
// 坿±ºã«å¿…è¦ãªç¥¨æ•°
const int need = N / 2;
// need + 0 票ã®é›†åˆã€need + 1 票ã®é›†åˆã€need + 2 ç¥¨ä»¥ä¸Šã®æ¡ˆã®æ•°
int zero = 0, one = 0, two = 0;
for(int i = 0; i < M; i++) {
if(agree[i] == need) zero |= 1 << i;
if(agree[i] == need + 1) one |= 1 << i;
if(agree[i] >= need + 2) two++;
}
// sum[s][d] = 案ã®é›†åˆã‚’ s ã«çµžã£ãŸã¨ãã€ãã®ã†ã¡ d 個ã«è³›æˆã—ã¦ã„ã‚‹äººã®æ•°
for(int i = 0; i < N; i++) {
const int a = A[i];
sum[a][popcnt(a)]++;
}
// é«˜é€Ÿã‚¼ãƒ¼ã‚¿å¤‰æ› (下ä½é›†åˆã«ç´¯ç©å’Œ)
for(int d = 0; d < M; d++) for(int s = 0; s < 1 << M; s++) if(s & 1 << d) {
const int t = s ^ 1 << d, i = popcnt(s);
sum[t][i - 1] += sum[s][i];
}
// 求ã‚ãŸã„ã‚‚ã®ã‚’作る
for(int d = 0; d < M; d++) for(int s = 0; s < 1 << M; s++) if(s & 1 << d) {
const int t = s ^ 1 << d;
for(int i = 0; i < M; i++) sum[s][i] += sum[t][i] - sum[s][i + 1];
}
// å„ s ã«å¯¾ã— d ã® first min, second min を求ã‚ã‚‹
for(int s = 0; s < 1 << M; s++) for(int d = M; d--; ) {
if(sum[s][d] < 1) continue;
if(sum[s][d] == 1) {
mn[s][1] = mn[s][0];
mn[s][0] = d;
}
else {
mn[s][0] = d;
mn[s][1] = d;
}
}
// å„è°å“¡ã«å¯¾ã—ç”ãˆã‚’求ã‚る。
for(int i = 0; i < N; i++) printf("%d\n", [&](int a) -> int {
const int ZERO = (zero & ~a) | (one & a);
const int rejected = mn[ZERO][mn[ZERO][0] == popcnt(a & ZERO)];
return two + popcnt(one | ZERO) - rejected;
}(A[i]));
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |