QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687479#6471. Binary TransformationsLaVuna47#WA 1ms3656kbC++201.7kb2024-10-29 19:14:282024-10-29 19:14:29

Judging History

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

  • [2024-10-29 19:14:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-10-29 19:14:28]
  • 提交

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(const vector<pair<ll, bool>>& dec, vector<ll> inc, int d, ll S)
{
	ll res = 0;
	FOR(i,0,d)
	{
		S -= dec[i].x;
		res += S;
		if(dec[i].y)
		{
			inc.pb(dec[i].x);
		}
	}
	sort(all(inc));
	for(auto item: inc)
	{
		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<pair<ll, bool>> dec;
	vector<ll> inc;
	FOR(i,0,n)
	{
		if(a[i] == '1' && b[i] == '1')
			dec.pb({C[i], true});
		else if(a[i] == '1' && b[i] == '0')
			dec.pb({C[i], false});
		else if(a[i] == '0' && b[i] == '1')
			inc.pb(C[i]);
	}
	sort(rall(dec));
	sort(all(inc));
	ll res = 1e18;
	FOR(d,0,sz(dec)+1)
	{
		res = min(res, f(dec, inc, 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

input:

5
5 2 6 1 5
01110
10011

output:

21

result:

ok single line: '21'

Test #2:

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

input:

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

output:

998

result:

wrong answer 1st lines differ - expected: '1498', found: '998'