QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780022#9802. Light Up the GridpeiTL 0ms0kbC++233.9kb2024-11-24 23:39:152024-11-29 22:50:40

Judging History

你现在查看的是最新测评结果

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

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 + cnt2 + cnt3 + cnt4 > 10 || sum >= res)
        return;
    cnt1++;
    x.a.x ^= 1;
    dfs(sum + a);
    cnt1--;
    x.a.x ^= 1;

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

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

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

    cnt2++;
    x.a.x ^= 1;
    x.a.y ^= 1;
    dfs(sum + b);
    cnt2--;
    x.a.x ^= 1;
    x.a.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.x ^= 1;
    x.b.x ^= 1;
    dfs(sum + c);
    cnt3--;
    x.a.x ^= 1;
    x.b.x ^= 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 ans1 = 0;
        vector<Node> brr = arr;
        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,b,c,d}));
                else {
                    y = arr[j];
                    x = q.back();
                    dfs(0);
                }
                if (res < temp) {
                    temp = res;
                    pos = j;
                }
            }
            ans1 += temp;
            q.push_back(arr[pos]);
            arr.erase(arr.begin() + pos);
        }

        int ans2 = 0;
        for (int i = 1; i <= n; i++) {
            if (brr[i] == tmp) {
                ans2 += 2 * min({a,b,c,d});
                brr.erase(brr.begin() + i);
                break;
            }
        }
        while (brr.size() > 1) {
            int pos = -1;
            temp = inf;
            res = inf;
            for (int j = 1; j < brr.size(); j++) {
                cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
                y = arr[j];
                x = tmp;
                dfs(0);
                if (res < temp) {
                    temp = res;
                    pos = j;
                }
            }
            ans2 += temp;
            tmp = brr[pos];
            brr.erase(brr.begin() + pos);
        }
        cout << min(ans1, ans2) << 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;
}

详细

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: