QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#782881#9802. Light Up the GridEZGGWA 30ms13844kbC++231.5kb2024-11-25 21:59:472024-11-25 21:59:48

Judging History

你现在查看的是测评时间为 2024-11-25 21:59:48 的历史记录

  • [2024-11-29 22:53:32]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:33ms
  • 内存:13972kb
  • [2024-11-25 21:59:48]
  • 评测
  • 测评结果:0
  • 用时:30ms
  • 内存:13844kb
  • [2024-11-25 21:59:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<ll>> dp(1 << 16, vector<ll>(17, 0x3f3f3f3f));
void init()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    b = min(2 * a, b);
    c = min(2 * b, c);
    d = min({2 * b, 2 * c, d});
    vector<ll> mp(16);
    mp[1] = mp[2] = mp[4] = mp[8] = a;
    mp[12] = mp[3] = b;
    mp[10] = mp[5] = c;
    mp[15] = d;
    mp[6] = mp[9] = min(b + c, 2 * a);
    mp[7] = mp[11] = mp[13] = mp[14] = min({b + a, c + a, d + a});
    mp[0] = min({a, b, c, d}) * 2;
    dp[0][0] = 0;
    for (int i = 1; i < (1 << 16); i++)
    {
        for (int j = 1; j <= 16; j++)
        {
            if (i & (1 << j - 1))
            {
                dp[i][j] = min(dp[i][j], dp[i ^ (1 << j - 1)][0] + mp[j - 1]);
                for (int k = 0; k < 16; k++)
                {
                    if (i & (1 << k))
                    {
                        dp[i][j] = min(dp[i][j], dp[i ^ (1 << j - 1)][k + 1] + mp[(j - 1 ^ k)]);
                    }
                }
            }
        }
    }
}
void solve()
{
    int n;
    cin >> n;
    int _ = 0;
    while (n--)
    {
        int a, b;
        cin >> a >> b;
        int tmp = a / 10 * 8 + a % 10 * 4 + b / 10 * 2 + b % 10;
        _ ^= 1 << ((15 ^ tmp));
    }
    cout << *min_element(dp[_].begin(), dp[_].end()) << '\n';
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt = 1;
    cin >> tt;
    init();
    while (tt--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 27ms
memory: 13828kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 22ms
memory: 13836kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

score: 0
Accepted
time: 26ms
memory: 13844kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 30ms
memory: 13792kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

28
26
30
30
34
30
36
32
34
36
30
38
28
32
32
26
26
34
34
34
32
34
38
32
26
32
32
32
28
32
26
36
28
30
36
34
40
28
32
28
26
30
34
34
38
30
34
32
32
32
36
26
36
36
30
36
38
34
36
28
36
34
32
28
28
32
32
32
36
34
28
30
26
28
26
32
30
34
32
32
30
32
32
28
28
28
36
36
32
32
34
34
32
36
32
26
30
34
30
28
...

result:

wrong answer 1st numbers differ - expected: '34', found: '28'