QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797669#9802. Light Up the Griducup-team4975#WA 152ms22488kbC++142.7kb2024-12-03 16:15:082024-12-03 16:15:08

Judging History

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

  • [2024-12-03 16:15:08]
  • 评测
  • 测评结果:WA
  • 用时:152ms
  • 内存:22488kb
  • [2024-12-03 16:15:08]
  • 提交

answer

#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'

#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif

#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif

#ifdef LOCAL
#define debugv(x)                   \
    cerr << setw(4) << #x << ":: "; \
    for (auto i : x)                \
        cerr << i << " ";           \
    cerr << endl
#else
#define debugv(x)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
    out << x.fir << " " << x.sec << endl;
    return out;
}

const int mod = 998244353;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 200020;
ll dp[(1 << 16) + 10][16], ans[(1 << 16) + 10];
int vis[(1 << 16) + 10][16];
int op[9] = {1, 2, 4, 8, 3, 12, 5, 10, 15};
int val[9];
void solve()
{
    int n, now = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
    	string s1, s2;
    	cin >> s1 >> s2;
    	int res = (s1[0] - '0') + (s1[1] - '0') * 2 + (s2[0] - '0') * 4 + (s2[1] - '0') * 8;
    	// cout << res << endl;
		now = (now | (1 << res));
    }
	// cout << now << el;
    ll as = inf;
    for (int i = 1; i < (1 << 16); i++) {
    	if ((i & now) == now) {
    		bitset<16>b = i;
    		// cout << i << " " << b << " " << ans[i]<< el;
    		as = min(as, ans[i]);
    	}
    }
    cout << as << el;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    cin >> T;
    int a1, a2, a3, a4;
    cin >> a1 >> a2 >> a3 >> a4;
    val[0] = val[1] = val[2] = val[3] = a1;
    val[4] = val[5] = a2;
    val[6] = val[7] = a3;
    val[8] = a4;
    
    for (int i = 0;  i < (1 << 16); i++) {
    	for (int j = 0; j < 16; j++) {
    		dp[i][j] = inf;
    	}
    	ans[i] = inf;
    }

    priority_queue<pair<int, PII>> q;
    dp[0][15] = 0;
    q.push({0, {0, 15}});

    while (!q.empty()) {
    	auto [v1, x] = q.top();
    	q.pop();
    	if (vis[x.fir][x.sec])
    		continue;
    	vis[x.fir][x.sec] = 1;

    	for (int i = 0; i < 9; i++) {
    		int state = x.sec ^ op[i];
    		int st = (x.fir | (1 << state));
    		if (vis[st][state])
    			continue;
    		int v = dp[x.fir][x.sec] + val[i];
    		if (v < dp[st][state]) {
				// cout << x.fir << " " << x.sec << " " << st << " " << state << " " << v << endl;
    			dp[st][state] = v;

    			q.push({-v, {st, state}});
    		}
    	}
    }

	for (int i = 1; i < (1 << 16); i++) {
		for (int j = 0; j < 15; j++) {
			ans[i] = min(ans[i], dp[i][j]);
		}
	}

    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 152ms
memory: 22488kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
3

result:

wrong answer 2nd numbers differ - expected: '2', found: '3'