QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780038#9802. Light Up the GridpeiTL 0ms0kbC++234.7kb2024-11-24 23:52:562024-11-24 23:52:56

Judging History

你现在查看的是测评时间为 2024-11-24 23:52:56 的历史记录

  • [2024-11-29 22:50:52]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-24 23:52:56]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-24 23:52:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define inf INT32_MAX
#define x first
#define y second
#define endl '\n'
struct Node {
    pair<int, int> a, b;
};

bool operator==(Node aa, Node bb) {
    return aa.a == bb.a && aa.b == bb.b;
}

int res;
int a, b, c, d;
int cnt1, cnt2, cnt3, cnt4;
Node x, y;

void dfs(int sum) {
    if (x == y) {
        res = min(res, sum);
        return;
    }
    if (cnt1 >= 8 || cnt2 >= 4 || cnt3 >= 4 || cnt4 >= 4) {
        return;
    }
    if (x.a.x != y.a.x) {
        cnt1++;
        x.a.x ^= 1;
        dfs(sum + a);
        cnt1--;
        x.a.x ^= 1;

        cnt2++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        dfs(sum + b);
        cnt2--;
        x.a.x ^= 1;
        x.a.y ^= 1;

        cnt3++;
        x.a.x ^= 1;
        x.b.x ^= 1;
        dfs(sum + c);
        cnt3--;
        x.a.x ^= 1;
        x.b.x ^= 1;

        cnt4++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + d);
        cnt4--;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
    }

    if (x.a.y != y.a.y) {
        cnt1++;
        x.a.y ^= 1;
        dfs(sum + a);
        cnt1--;
        x.a.y ^= 1;

        cnt2++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        dfs(sum + b);
        cnt2--;
        x.a.x ^= 1;
        x.a.y ^= 1;

        cnt3++;
        x.a.y ^= 1;
        x.b.y ^= 1;
        dfs(sum + c);
        cnt3--;
        x.a.y ^= 1;
        x.b.y ^= 1;

        cnt4++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + d);
        cnt4--;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
    }

    if (x.b.x != y.b.x) {
        cnt1++;
        x.b.x ^= 1;
        dfs(sum + a);
        cnt1--;
        x.b.x ^= 1;

        cnt2++;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + b);
        cnt2--;
        x.b.x ^= 1;
        x.b.y ^= 1;

        cnt3++;
        x.a.x ^= 1;
        x.b.x ^= 1;
        dfs(sum + c);
        cnt3--;
        x.a.x ^= 1;
        x.b.x ^= 1;

        cnt4++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + d);
        cnt4--;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
    }

    if (x.b.y != y.b.y) {
        cnt1++;
        x.b.y ^= 1;
        dfs(sum + a);
        cnt1--;
        x.b.y ^= 1;

        cnt2++;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + b);
        cnt2--;
        x.b.x ^= 1;
        x.b.y ^= 1;

        cnt3++;
        x.a.y ^= 1;
        x.b.y ^= 1;
        dfs(sum + c);
        cnt3--;
        x.a.y ^= 1;
        x.b.y ^= 1;

        cnt4++;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
        dfs(sum + d);
        cnt4--;
        x.a.x ^= 1;
        x.a.y ^= 1;
        x.b.x ^= 1;
        x.b.y ^= 1;
    }
}

void solve() {
    int t;
    cin >> t;
    cin >> a >> b >> c >> d;
    while (t--) {
        int n;
        cin >> n;
        vector<Node> arr(n + 1);
        for (int i = 1; i <= n; i++) {
            char aa, bb, cc, dd;
            cin >> aa >> bb;
            cin >> cc >> dd;
            arr[i].a.x = aa - '0';
            arr[i].a.y = bb - '0';
            arr[i].b.x = cc - '0';
            arr[i].b.y = dd - '0';
        }
        int temp, sum;
        int ans = 0;
        deque<Node> q;
        Node tmp = {{1, 1},
                    {1, 1}};
        q.push_back(tmp);
        while (arr.size() > 1) {
            int pos = -1;
            temp = inf;
            res = inf;
            for (int j = 1; j < arr.size(); j++) {
                cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
                if (q.back() == arr[j])
                    res = min(res, 2 * min(a, min(b, min(c, d))));
                else {
                    y = arr[j];
                    x = q.back();
                    dfs(0);
                }
                if (res < temp) {
                    temp = res;
                    pos = j;
                }
            }
            ans += temp;
            q.push_back(arr[pos]);
            arr.erase(arr.begin() + pos);
        }
        cout << ans << endl;
    }
}

signed main() {
#ifdef ONLINE_JUDGE
#else
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:


result: