답안 #149119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149119 2019-09-01T05:46:33 Z 서울대학교 연구공원 944동 삼성전자서울대연구소(#3600, ho94949, dotorya, zigui) HicCup (FXCUP4_hiccup) C++17
24 / 100
41 ms 3456 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;
	
	for (int i = 0; i + 1 < N; i++) if (S[i] == 'H' && S[i + 1] == '!') 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;
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 35 ms 3328 KB Output is correct
6 Correct 14 ms 3328 KB Output is correct
7 Correct 14 ms 3456 KB Output is correct
8 Correct 37 ms 3288 KB Output is correct
9 Correct 34 ms 3200 KB Output is correct
10 Correct 14 ms 3352 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 35 ms 3328 KB Output is correct
6 Correct 14 ms 3328 KB Output is correct
7 Correct 14 ms 3456 KB Output is correct
8 Correct 37 ms 3288 KB Output is correct
9 Correct 34 ms 3200 KB Output is correct
10 Correct 14 ms 3352 KB Output is correct
11 Correct 16 ms 3456 KB Output is correct
12 Correct 13 ms 3328 KB Output is correct
13 Correct 12 ms 3328 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 14 ms 3328 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Incorrect 41 ms 3328 KB Output isn't correct
20 Halted 0 ms 0 KB -