Submission #32736365


Source Code Expand

#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>

using namespace std;

typedef pair<int, char> P;

int N;
string S;

int f(vector<int>& child, vector<int>& adult, int X) {
	if (X == N) { return child[N]; }
	if (X == 0) { return adult[N]; }
	return (adult[N] - adult[X]) + child[X];
}

int main() {
	cin >> N;
	cin >> S;
	vector<P> person(N);
	for (int i = 0; i < N; i++) {
		int W;
		cin >> W;
		person[i] = make_pair(W, S[i]);
	}
	sort(person.begin(), person.end());

	if (N == 1) { 
		cout << 1 << endl;
		return 0;
	}

	vector<int> child(N + 1, 0);
	vector<int> adult(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		if (person[i - 1].second == '1') {
			child[i] = child[i - 1];
			adult[i] = adult[i - 1] + 1;
		}
		else {
			child[i] = child[i - 1] + 1;
			adult[i] = adult[i - 1];
		}
	}

	//for (int i = 0; i <= N; i++) {
	//	cout << child[i] << " " << flush;
	//}
	//cout << endl;
	//for (int i = 0; i <= N; i++) {
	//	cout << adult[i] << " " << flush;
	//}
	//cout << endl;

	int max_correct = 0;
	int ans = person[0].first;
	for (int i = 0; i <= N; i++) {
		if (i > 0 && i < N && person[i].first == person[i - 1].first) {
			continue;
		}
		int correct = f(child, adult, i);
		//cout << i << " : " <<  correct << endl;
		if (correct > max_correct) {
			max_correct = correct;
		}
	}
	cout << max_correct << endl;
}

Submission Info

Submission Time
Task C - Robot Takahashi
User NoKmono
Language C++ (GCC 9.2.1)
Score 300
Code Size 1436 Byte
Status AC
Exec Time 84 ms
Memory 6820 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:59:6: warning: unused variable ‘ans’ [-Wunused-variable]
   59 |  int ans = person[0].first;
      |      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 35
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
Case Name Status Exec Time Memory
example_00.txt AC 7 ms 3484 KiB
example_01.txt AC 2 ms 3592 KiB
example_02.txt AC 2 ms 3456 KiB
hand_00.txt AC 82 ms 6752 KiB
hand_01.txt AC 78 ms 6816 KiB
hand_02.txt AC 74 ms 6708 KiB
hand_03.txt AC 78 ms 6724 KiB
hand_04.txt AC 67 ms 6668 KiB
hand_05.txt AC 2 ms 3484 KiB
hand_06.txt AC 3 ms 3620 KiB
random_00.txt AC 82 ms 6672 KiB
random_01.txt AC 80 ms 6708 KiB
random_02.txt AC 84 ms 6816 KiB
random_03.txt AC 80 ms 6720 KiB
random_04.txt AC 80 ms 6616 KiB
random_05.txt AC 79 ms 6716 KiB
random_06.txt AC 81 ms 6668 KiB
random_07.txt AC 80 ms 6640 KiB
random_08.txt AC 74 ms 6672 KiB
random_09.txt AC 75 ms 6640 KiB
random_10.txt AC 74 ms 6760 KiB
random_11.txt AC 73 ms 6816 KiB
random_12.txt AC 74 ms 6716 KiB
random_13.txt AC 74 ms 6724 KiB
random_14.txt AC 73 ms 6752 KiB
random_15.txt AC 79 ms 6692 KiB
random_16.txt AC 78 ms 6752 KiB
random_17.txt AC 80 ms 6692 KiB
random_18.txt AC 78 ms 6720 KiB
random_19.txt AC 77 ms 6820 KiB
random_20.txt AC 81 ms 6584 KiB
random_21.txt AC 80 ms 6656 KiB
random_22.txt AC 83 ms 6588 KiB
random_23.txt AC 82 ms 6700 KiB
random_24.txt AC 82 ms 6700 KiB