Submission #44746830


Source Code Expand

Copy
import std;
void main () {
int H, W; readln.read(H, W);
char[][] c = new char[][](H, 0);
foreach (i; 0..H) {
c[i] = readln.chomp.dup;
}
solve(H, W, c);
}
void solve (int H, int W, char[][] c) {
int[][] lCount = new int[][](H, 26);
int[][] lInfo = new int[][](H, 2);
int[][] cCount = new int[][](W, 26);
int[][] cInfo = new int[][](W, 2);
// Info [0] [1]
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import std;

void main () {
    int H, W; readln.read(H, W);
    char[][] c = new char[][](H, 0);
    foreach (i; 0..H) {
        c[i] = readln.chomp.dup;
    }

    solve(H, W, c);
}

void solve (int H, int W, char[][] c) {
    int[][] lCount = new int[][](H, 26);
    int[][] lInfo = new int[][](H, 2);

    int[][] cCount = new int[][](W, 26);
    int[][] cInfo = new int[][](W, 2);

    // Info は [0] が種類数 [1] が総数 とする

    // 行(line)
    foreach (i; 0..H) {
        foreach (j; 0..W) {
            lCount[i][ c[i][j]-'a' ]++;
        }
        foreach (x; lCount[i]) {
            if (x != 0) {
                lInfo[i][0]++;
            }
            lInfo[i][1] += x;
        }
    }

    // 列(column)
    foreach (j; 0..W) {
        foreach (i; 0..H) {
            cCount[j][ c[i][j]-'a' ]++;
        }
        foreach (x; cCount[j]) {
            if (x != 0) {
                cInfo[j][0]++;
            }
            cInfo[j][1] += x;
        }
    }

    struct trio {
        int type;
        int color;
    }

    // 操作
    DList!trio Q;
    int lOp = 0, cOp = 0;

    while (true) {
        // 行
        foreach (i; 0..H) {
            if (lInfo[i][0] == 1 && 2 <= lInfo[i][1]) {
                lOp++;
                lInfo[i][] = 0;
                int co;
                foreach (idx, x; lCount[i]) {
                    if (x != 0) {
                        co = cast(int) idx;
                        break;
                    }
                }
                // 列側に削除依頼を出す
                Q.insertBack(trio(0, co));
            }
        }
        // 列
        foreach (j; 0..W) {
            if (cInfo[j][0] == 1 && 2 <= cInfo[j][1]) {
                cOp++;
                cInfo[j][] = 0;
                int co;
                foreach (idx, x; cCount[j]) {
                    if (x != 0) {
                        co = cast(int) idx;
                        break;
                    }
                }
                // 行側に削除依頼を出す
                Q.insertBack(trio(1, co));
            }
        }
        if (Q.empty) {
            break;
        } else {
            while (!Q.empty) {
                auto head = Q.front; Q.removeFront;
                if (head.type == 0) {
                    // 列削除
                    foreach (j; 0..W) {
                        cCount[j][head.color]--;
                        cInfo[j][1]--;
                        if (cCount[j][head.color] == 0) {
                            cInfo[j][0]--;
                        }
                    }
                } else {
                    // 行削除
                    foreach (i; 0..H) {
                        lCount[i][head.color]--;
                        lInfo[i][1]--;
                        if (lCount[i][head.color] == 0) {
                            lInfo[i][0]--;
                        }
                    }
                }
            }
        }
    }

    writeln((H-lOp)*(W-cOp));
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

Submission Info

Submission Time
Task D - Magical Cookies
User InTheBloom
Language D (DMD 2.104.0)
Score 400
Code Size 3284 Byte
Status AC
Exec Time 60 ms
Memory 12412 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 400 / 400
Status
AC × 3
AC × 36
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt
Case Name Status Exec Time Memory
sample00.txt AC 1 ms 3528 KB
sample01.txt AC 1 ms 3548 KB
sample02.txt AC 1 ms 3620 KB
testcase00.txt AC 23 ms 12016 KB
testcase01.txt AC 26 ms 11948 KB
testcase02.txt AC 27 ms 12076 KB
testcase03.txt AC 31 ms 12000 KB
testcase04.txt AC 33 ms 11916 KB
testcase05.txt AC 30 ms 12092 KB
testcase06.txt AC 32 ms 11804 KB
testcase07.txt AC 34 ms 11924 KB
testcase08.txt AC 34 ms 11856 KB
testcase09.txt AC 40 ms 12344 KB
testcase10.txt AC 29 ms 11632 KB
testcase11.txt AC 37 ms 12000 KB
testcase12.txt AC 40 ms 12244 KB
testcase13.txt AC 37 ms 11524 KB
testcase14.txt AC 43 ms 12296 KB
testcase15.txt AC 36 ms 12108 KB
testcase16.txt AC 38 ms 11864 KB
testcase17.txt AC 47 ms 12320 KB
testcase18.txt AC 45 ms 12032 KB
testcase19.txt AC 48 ms 12216 KB
testcase20.txt AC 38 ms 12412 KB
testcase21.txt AC 42 ms 11624 KB
testcase22.txt AC 46 ms 12124 KB
testcase23.txt AC 44 ms 11308 KB
testcase24.txt AC 53 ms 12268 KB
testcase25.txt AC 60 ms 12220 KB
testcase26.txt AC 58 ms 12264 KB
testcase27.txt AC 60 ms 12308 KB
testcase28.txt AC 58 ms 12348 KB
testcase29.txt AC 47 ms 12344 KB
testcase30.txt AC 48 ms 12340 KB
testcase31.txt AC 47 ms 12320 KB
testcase32.txt AC 45 ms 12248 KB


2025-04-15 (Tue)
11:13:16 +00:00