Submission #48463494
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import std;
void main () {
int H, W, K; readln.read(H, W, K);
string[] S = new string[](H);
foreach (i; 0..H) S[i] = readln.chomp;
solve(H, W, K, S);
}
void solve (int H, int W, int K, string[] S) {
/* 1Dなら貪欲で行ける -> 縦を全探索して貪欲すれば良い */
int ans = int.max;
/* チーム分け */
int[] idx = new int[](H);
string[][] T = new string[][](H, 0);
int[] count = new int[](H);
int check () {
int len = 0;
foreach (x; idx) len = max(len, x+1);
T.length = len;
count.length = len;
count[] = 0;
foreach (ref t; T) t.length = 0;
foreach (i, x; idx) T[x] ~= S[i];
int res = cast(int) T.length-1;
foreach (i; 0..W) {
foreach (j, tt; T) {
int sum = 0;
foreach (t; tt) {
if (t[i] == '1') sum++;
}
if (K < count[j] + sum) {
count[] = 0;
res++;
break;
}
}
foreach (j, tt; T) {
int sum = 0;
foreach (t; tt) {
if (t[i] == '1') sum++;
}
count[j] += sum;
}
foreach (c; count) if (K < c) return int.max;
}
return res;
}
foreach (e; enumSubset(H-1)) {
int cur = 0;
idx[] = 0;
foreach (x; e) {
idx[x] = -1;
}
foreach (ref x; idx) {
if (x == -1) x = cur++;
else x = cur;
}
ans = min(ans, check());
}
writeln(ans);
}
void read (T...) (string S, ref T args) {
auto buf = S.split;
foreach (i, ref arg; args) {
arg = buf[i].to!(typeof(arg));
}
}
import std.format : format;
import std.exception : enforce;
struct SubsetIndexes {
long bit;
int right;
long MAX;
int[] res;
this (int N) {
MAX = 1<<N;
res = new int[](N);
right = 0;
}
auto front () const { return res[0..right]; }
bool empty () const { return bit == MAX; }
void popFront () {
bit++;
int i = 0;
for (int j = 1, val = 0; j < MAX; j <<= 1, val++) if (0 < (j&bit)) res[i++] = val;
right = i;
}
}
struct SubsetItems (T) {
import std.traits : ForeachType, Unconst;
alias E = Unconst!(ForeachType!T)[];
E arr;
E res;
int right;
SubsetIndexes subsets;
this (T arr) {
this.arr = arr.dup;
res = new E(arr.length);
subsets = enumSubset(cast(int) arr.length);
}
auto front () const { return res[0..right]; }
bool empty () const { return subsets.empty; }
void popFront () {
subsets.popFront;
int i = 0;
foreach (s; subsets.front) res[i++] = arr[s];
right = i;
}
}
auto enumSubset (T) (T arr)
if (is (T == E[], E) || is (T == E[n], E, size_t n))
{
return SubsetItems!(T)(arr);
}
auto enumSubset (int N)
in {
enforce(0 <= N && N <= 60, format("N must satisfy 0 <= N <= 60. Now N = %s.", N));
}
do {
return SubsetIndexes(N);
}
Submission Info
Submission Time |
|
Task |
E - Dividing Chocolate |
User |
InTheBloom |
Language |
D (DMD 2.104.0) |
Score |
500 |
Code Size |
3327 Byte |
Status |
AC |
Exec Time |
97 ms |
Memory |
3912 KB |
Compile Error
/home/runner/.dub/packages/mir-algorithm/3.20.4/mir-algorithm/source/mir/serde.d(52,9): Deprecation: alias this for classes/interfaces is deprecated
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01, sample_02, sample_03 |
All |
max_01, max_02, max_03, max_04, max_05, max_06, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, sample_01, sample_02, sample_03 |
Case Name |
Status |
Exec Time |
Memory |
max_01 |
AC |
24 ms |
3724 KB |
max_02 |
AC |
2 ms |
3632 KB |
max_03 |
AC |
24 ms |
3756 KB |
max_04 |
AC |
24 ms |
3588 KB |
max_05 |
AC |
97 ms |
3812 KB |
max_06 |
AC |
2 ms |
3684 KB |
random_01 |
AC |
1 ms |
3824 KB |
random_02 |
AC |
7 ms |
3652 KB |
random_03 |
AC |
28 ms |
3664 KB |
random_04 |
AC |
2 ms |
3772 KB |
random_05 |
AC |
19 ms |
3848 KB |
random_06 |
AC |
1 ms |
3784 KB |
random_07 |
AC |
1 ms |
3764 KB |
random_08 |
AC |
6 ms |
3756 KB |
random_09 |
AC |
23 ms |
3740 KB |
random_10 |
AC |
1 ms |
3792 KB |
sample_01 |
AC |
1 ms |
3912 KB |
sample_02 |
AC |
1 ms |
3844 KB |
sample_03 |
AC |
1 ms |
3696 KB |