QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687418#6471. Binary TransformationsLaVuna47#WA 0ms3856kbC++201.8kb2024-10-29 18:55:392024-10-29 18:55:39

Judging History

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

  • [2024-10-29 18:55:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-10-29 18:55:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;

#ifdef ONPC
mt19937 rnd(228);
#endif


ll f(vector<vector<ll>> vals, int d, ll S)
{
	ll res = 0;
	FOR(i,0,d)
	{
		S -= vals[3][i];
		res += S;
		vals[1].pb(vals[3][i]);
	}
	sort(all(vals[1]));
	for(auto item: vals[2])
	{
		S -= item;
		res += S;
	}
	for(auto item: vals[1])
	{
		S += item;
		res += S;
	}
	return res;
}

int solve()
{
	int n;
	if(!(cin >> n))
		return 1;
	vector<ll> C(n);
	FOR(i,0,n) cin >> C[i];
	string a, b;
	cin >> a >> b;
	ll S = 0;
	FOR(i,0,n) if(a[i] == '1') S += C[i];
	vector<vector<ll>> vals(4);
	FOR(i,0,n)
	{
		if(a[i] == '1' && b[i] == '1')
			vals[3].pb(C[i]);
		else if(a[i] == '1' && b[i] == '0')
			vals[2].pb(C[i]);
		else if(a[i] == '0' && b[i] == '1')
			vals[1].pb(C[i]);
	}
	sort(rall(vals[3]));
	sort(rall(vals[2]));
	sort(all(vals[1]));
	ll res = 1e18;
	FOR(d,0,sz(vals[3])+1)
	{
		res = min(res, f(vals, d, S));
	}
	cout << res << '\n';
	return 0;	
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1e9;
	//cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
			break;
			
		#ifdef ONPC
			cerr << "_________________________________\n";
		#endif
	}
	#ifdef ONPC
		cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

5
5 2 6 1 5
01110
10011

output:

21

result:

ok single line: '21'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

10
54 57 56 56 34 26 62 57 94 93
1101100111
0111110011

output:

1498

result:

ok single line: '1498'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3784kb

input:

100
13497 84812 46650 96837 47518 81363 69563 49672 62222 59492 2399 70142 66019 23108 34561 48256 89591 70076 35039 20871 56909 44505 91578 96372 47174 73772 45594 75368 50125 79114 39144 60524 75020 85709 33811 68779 99668 89361 25932 45107 41881 70392 77449 37880 20372 49639 24933 76529 43903 136...

output:

86253225

result:

wrong answer 1st lines differ - expected: '83548857', found: '86253225'