Submission #613040

# Submission time Handle Problem Language Result Execution time Memory
613040 2022-07-30T03:03:44 Z penguinhacker HicCup (FXCUP4_hiccup) C++17
Compilation error
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;
	}
	reverse(adj[u].begin(), adj[u].end());
	return 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(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.top()];
		}
	}
	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:27:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for (int i=0; i<s.size(); ++i) {
      |                ~^~~~~~~~~
hiccup.cpp:29:29: error: 'n2' was not declared in this scope; did you mean 'n'?
   29 |    adj[stk.top()].push_back(n2);
      |                             ^~
      |                             n