编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#39611 #1001. A. 神秘谜题 Memory Limit Exceeded 0 755 ms 525684 K C++ / 2.6 K 管工94-郑春旭 2020-07-16 11:20:08
显示原始代码
#include <bits/stdc++.h>
using namespace std;
int val[10];
int a[5][5];
void cal();
void rotate(int cur);
void rerotate(int cur);
int chin(int step, int point, int end, int rot);
int main() {
    int T;
    cin >> T;
    while (T--) {
        int k;
        cin >> k;
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= 4; j++) {
                cin >> a[i][j];
            }
        }
        rerotate(1);
        cout << chin(0, 0, 2 * k, 1);
    }
    return 0;
}

void cal() {
    val[0] = a[1][1] + a[1][2] + a[2][1] + a[2][2];
    val[1] = a[1][3] + a[1][4] + a[2][3] + a[2][4];
    val[2] = a[3][1] + a[3][2] + a[4][1] + a[4][2];
    val[3] = a[3][3] + a[3][4] + a[4][3] + a[4][4];
    val[4] = a[2][2] + a[3][3] + a[2][3] + a[3][2];
    val[5] = a[1][2] + a[1][3] + a[2][2] + a[2][3];
    val[6] = a[3][2] + a[3][3] + a[4][2] + a[4][3];
    val[7] = a[2][1] + a[2][2] + a[3][1] + a[3][2];
    val[8] = a[2][3] + a[2][4] + a[3][3] + a[3][4];
}
void rotate(int cur) {
    int temp[2][2];
    int x, y;
    if (cur == 0) {
        x = 1;
        y = 1;
    }
    if (cur == 1) {
        x = 1;
        y = 3;
    }
    if (cur == 2) {
        x = 3;
        y = 1;
    }
    if (cur == 3) {
        x = 3;
        y = 3;
    }
    if (cur == 4) {
        x = 2;
        y = 2;
    }
    if (cur == 5) {
        x = 1;
        y = 2;
    }
    if (cur == 6) {
        x = 3;
        y = 2;
    }
    if (cur == 7) {
        x = 2;
        y = 1;
    }
    if (cur == 8) {
        x = 2;
        y = 3;
    }
    temp[0][0] = a[x][y + 1];
    temp[1][0] = a[x][y];
    temp[0][1] = a[x + 1][y + 1];
    temp[1][1] = a[x + 1][y];
    a[x][y] = temp[0][0];
    a[x][y + 1] = temp[0][1];
    a[x + 1][y] = temp[1][0];
    a[x + 1][y + 1] = temp[1][1];
    cal();
}
void rerotate(int cur) {
    int temp[2][2];
    int x, y;
    if (cur == 0) {
        x = 1;
        y = 1;
    }
    if (cur == 1) {
        x = 1;
        y = 3;
    }
    if (cur == 2) {
        x = 3;
        y = 1;
    }
    if (cur == 3) {
        x = 3;
        y = 3;
    }
    if (cur == 4) {
        x = 2;
        y = 2;
    }
    if (cur == 5) {
        x = 1;
        y = 2;
    }
    if (cur == 6) {
        x = 3;
        y = 2;
    }
    if (cur == 7) {
        x = 2;
        y = 1;
    }
    if (cur == 8) {
        x = 2;
        y = 3;
    }
    temp[0][0] = a[x + 1][y];
    temp[1][0] = a[x + 1][y + 1];
    temp[0][1] = a[x][y];
    temp[1][1] = a[x][y + 1];
    a[x][y] = temp[0][0];
    a[x][y + 1] = temp[0][1];
    a[x + 1][y] = temp[1][0];
    a[x + 1][y + 1] = temp[1][1];
    cal();
}
int chin(int step, int point, int end, int rot) {
    rotate(rot);
    if (step == end) {
        return point;
    }
    if (step % 2 == 0) {
        int maxAns = 0;
        for (int i = 0; i < 9; i++) {
            int v = chin(step + 1, point + val[i], end, i);
            if (v > maxAns)
                maxAns = v;
            rerotate(i);
        }
        return maxAns;
    } else if (step % 2 == 1) {
        int minAns = INT_MAX;
        for (int i = 0; i < 9; i++) {
            int v = chin(step + 1, point + val[i], end, i);
            if (v < minAns)
                minAns = v;
            rerotate(i);
        }
        return minAns;
    }
    return 0;
}
子任务 #1
Memory Limit Exceeded
得分:0
测试点 #1
Memory Limit Exceeded
得分:0
用时:366 ms
内存:525684 KiB

输入文件(1.in

200000
2 526767110
2 724642759
2 567837900
2 104106873
2 357915481
2 33997211
2 444788944
2 
<1586974 bytes omitted>

答案文件(1.ans

526767110
877985729
361528077
330887284
116239149
82537142
510237286
843295274
453728745
55
<2188330 bytes omitted>

用户输出

0
测试点 #2
Memory Limit Exceeded
得分:0
用时:389 ms
内存:525604 KiB

输入文件(2.in

200000
2 515979308
2 512702340
2 684230440
2 488136957
2 598252313
2 283603971
2 349877373
2
<1586842 bytes omitted>

答案文件(2.ans

515979308
5115816
679905408
899606653
372667236
114362215
302756634
473674072
520218589
525
<2192841 bytes omitted>

用户输出

0