답안 #613050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613050 2022-07-30T03:08:39 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], ans=69696969;
stack<int> stk;
vector<int> adj[mxN];

void dfs(int u) {
	for (int v : adj[u])
		dfs(v);
	reverse(adj[u].begin(), adj[u].end());
	int cur=0;
	for (int i=0; i<adj[u].size(); ++i) {
		cur+=cnt[adj[u][i]];
		ans=min(ans, cur/(i+1));
	}
}

int HicCup(string s) {
	stk.push(0);
	for (int i=0; i<s.size(); ++i) {
		if (s[i]=='H') {
			adj[stk.top()].push_back(n);
			stk.push(n++);
		} else if (s[i]=='C') {
			stk.pop();
			if (stk.empty())
				return -1;
		} else {
			if (!i||s[i-1]=='H')
				return -1;
			++cnt[stk.top()];
		}
	}
	if (stk.size()!=1||n==1)
		return -1;
	dfs();
	return ans;
}

Compilation message

hiccup.cpp: In function 'void dfs(int)':
hiccup.cpp:15:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for (int i=0; i<adj[u].size(); ++i) {
      |                ~^~~~~~~~~~~~~~
hiccup.cpp: In function 'int HicCup(std::string)':
hiccup.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i=0; i<s.size(); ++i) {
      |                ~^~~~~~~~~
hiccup.cpp:39:6: error: too few arguments to function 'void dfs(int)'
   39 |  dfs();
      |      ^
hiccup.cpp:10:6: note: declared here
   10 | void dfs(int u) {
      |      ^~~