Submission #1292508


Source Code Expand

#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;


int replace(int N, char S[]) {
	vector<int> vs[4];
	REP(i, 4)vs[i].resize(100000);
	int len[4] = { 0,0,0,0 };
	REP(i, N) {
		if (S[i] == 'I') vs[0][len[0]++] = i;
		if (S[i] == 'J') vs[1][len[1]++] = i;
		if (S[i] == 'P') vs[2][len[2]++] = i;
		if (S[i] == 'C') vs[3][len[3]++] = i;
	}
	REP(i, 4)vs[i].resize(len[i]);

	int res = 4;
	REP(pat, 1 << 4) {
		int next = 0;
		int cur = 0;
		bool ok = true;
		REP(i, 4) {
			if (pat & (1 << i)) {
				vector<int>::iterator p = lower_bound(vs[i].begin(), vs[i].end(), next);
				if (p == vs[i].end()) {
					ok = false;
					break;
				}
				else {
					next = *p + 1;
				}
			}
			else {
				if (next < N) {
					++cur;
					++next;
				}
				else {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			res = min(res, cur);
		}
	}

	return res;
}
int main() {
	replace(4, "ICCP");
}

Submission Info

Submission Time
Task A - 国際情報オリンピック日本代表プログラミングコンテスト (Welcome to IJPC)
User eukaryo
Language IOI-Style C++ (GCC 5.4.1)
Score 0
Code Size 1001 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:54:19: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  replace(4, "ICCP");
                   ^
./grader.cpp: In function ‘int main()’:
./grader.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%s", &N, S);
                       ^
/tmp/cc76XKY5.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccbtdReO.o:Main.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status