Submission #149090

# Submission time Handle Problem Language Result Execution time Memory
149090 2019-09-01T05:43:52 Z 서울대학교 연구공원 944동 삼성전자서울대연구소(#3600, ho94949, dotorya, zigui) HicCup (FXCUP4_hiccup) C++17
24 / 100
28 ms 3328 KB
#include "hiccup.h"

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;


int HicCup(std::string S) {
	int N = S.size(), i, j;

	int c = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'H') c++;
		if (S[i] == 'C') c--;
		if (c < 0) return -1;
	}
	if (c != 0) return -1;

	int p = N;
	for (int i = N - 1; i >= 0; i--) if (S[i] == 'C') p = i;
	for (int i = 0; i < p; i++) if (S[i] == '!') return -1;

	int st = 0, en = INF, mi, rv = -1;
	while (st <= en) {
		mi = (st + en) / 2;
	
		vector <ll> Vr;
		Vr.push_back(0);
		int i;
		for (i = 0; i < N; i++) {
			if (S[i] == 'H') Vr.push_back(0);
			else if (S[i] == 'C') {
				if (Vr.back() > 0) break;
				Vr.pop_back();
				Vr.back() += mi;
			}
			else Vr.back()--;
		}
		if (i >= N && Vr.back() <= 0) {
			rv = mi;
			st = mi + 1;
		}
		else en = mi - 1;
	}
	return rv;
}

Compilation message

hiccup.cpp:25:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 
hiccup.cpp:26:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:57:20: warning: unused variable 'i' [-Wunused-variable]
  int N = S.size(), i, j;
                    ^
hiccup.cpp:57:23: warning: unused variable 'j' [-Wunused-variable]
  int N = S.size(), i, j;
                       ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 28 ms 3328 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 27 ms 3328 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 28 ms 3328 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 27 ms 3328 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 19 ms 3328 KB Output is correct
12 Correct 13 ms 3328 KB Output is correct
13 Correct 13 ms 3200 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Incorrect 23 ms 3328 KB Output isn't correct
16 Halted 0 ms 0 KB -