답안 #613025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613025 2022-07-30T03:01:10 Z penguinhacker HicCup (FXCUP4_hiccup) C++17
컴파일 오류
0 ms 0 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN=1e6+2;
int n=1, cnt[mxN];
stack<int> stk;
vector<int> adj[mxN];

bool dfs(int u, int x) {
	for (int v : adj[u])
		if (!dfs(v, x))
			return 0;
	reverse(adj[u].begin(), adj[u].end());
	int cur=0;
	for (int i=0; i<adj[u].size(); ++i) {
		cur+=cnt[adj[u][i]]-x;
		if (cur<0)
			return 0;
	}
	return 1;
}

int HicCup(string s) {
	stk.push(0);
	for (int i=0; i<s.size(); ++i) {
		if (s[i]=='H') {
			adj[stk.back()].push_back(n2);
			stk.push(n2++);
		} else if (s[i]=='C') {
			stk.pop();
			if (stk.empty())
				return -1;
		} else {
			if (!i||s[i-1]=='H')
				return -1;
			++cnt[stk.back()];
		}
	}
	if (stk.size()!=1)
		return -1;
	int lb=0, rb=1e6;
	while(lb<rb) {
		int mid=(lb+rb+1)/2;
		if (dfs(0, mid))
			lb=mid;
		else
			rb=mid-1;
	}
	return lb;
}

Compilation message

hiccup.cpp: In function 'bool dfs(int, int)':
hiccup.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for (int i=0; i<adj[u].size(); ++i) {
      |                ~^~~~~~~~~~~~~~
hiccup.cpp: In function 'int HicCup(std::string)':
hiccup.cpp:26:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for (int i=0; i<s.size(); ++i) {
      |                ~^~~~~~~~~
hiccup.cpp:28:12: error: 'class std::stack<int>' has no member named 'back'
   28 |    adj[stk.back()].push_back(n2);
      |            ^~~~
hiccup.cpp:28:30: error: 'n2' was not declared in this scope; did you mean 'n'?
   28 |    adj[stk.back()].push_back(n2);
      |                              ^~
      |                              n
hiccup.cpp:37:14: error: 'class std::stack<int>' has no member named 'back'
   37 |    ++cnt[stk.back()];
      |              ^~~~