제출 #1129596

#제출 시각아이디문제언어결과실행 시간메모리
1129596am_aadvikJJOOII 2 (JOI20_ho_t2)C++17
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
using namespace std;

int nxtk(string& s, int i, vector<vector<vector<int>>>& pre, int j, int k) {
	int ans = j;
	for (int x = 0; x < 20; ++x)
		if ((k >> x) & 1) {
			ans = pre[ans][i][x] + 1;
			if (ans == -1) break;
		}
	return ans;
}

int main()
{
	int n, k; cin >> n >> k;
	string s, l = "JOI"; cin >> s; int lg = log2(n) + 1;
	vector<vector<vector<int>>> pre(n + 1, vector<vector<int>>(3, vector<int>(20, -2)));
	for(int x = 0; x < lg; ++x)
		for (int i = 0; i < 3; ++i)
			for (int j = n - 1; j >= 0; --j)
				if(x == 0) pre[j][i][x] = ((s[j] == l[i]) ? j : pre[j + 1][i][x]);
				else pre[j][i][x] = ((pre[j][i][x - 1] == -2)? -2: pre[pre[j][i][x - 1] + 1][i][x - 1]);

	int ans = n + 1;
	for (int f = 0; f < n; ++f) {
		int l = f + 2, r = n - 1;
		while (l <= r) {
			int e = (l + r) / 2, j = f;
			bool ok = 1;
			for (int i = 0; i < 3; j--, ++i) {
				j = nxtk(s, i, pre, j, k);
				if ((j == -1) || (j > (e + 1))) { ok = 0; break; }
			}

			if (ok) ans = min(ans, e - f + 1), r = e - 1;
			else l = e + 1;
		}
	}
	cout << ((ans == (n + 1)) ? -1 : ans - (3 * k)) << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:49: error: 'log2' was not declared in this scope; did you mean 'lg'?
   18 |         string s, l = "JOI"; cin >> s; int lg = log2(n) + 1;
      |                                                 ^~~~
      |                                                 lg