Submission #150493

# Submission time Handle Problem Language Result Execution time Memory
150493 2019-09-01T08:31:12 Z Little Piplup(#3742, gratus907, DHdroid, coffeetea99) HicCup (FXCUP4_hiccup) C++17
100 / 100
828 ms 20568 KB
#include "hiccup.h"
#include<bits/stdc++.h>
using std::vector;
using std::cout;
using std::string;
using std::endl;
using std::stack;
int ans(string S) {
   int N = S.size();
   if ( S[0] != 'H' ) return -1;

   vector<int> parse;
   int temp = 0;
   for ( int i = 0 ; i < N ; ++i ) {
      if ( S[i] == 'H' ) {
         if ( temp ) {
            parse.push_back(temp);
            temp = 0;
         }
         parse.push_back(-2);
      } else if ( S[i] == 'C' ) {
         if ( temp ) {
            parse.push_back(temp);
            temp = 0;
         }
         parse.push_back(-1);
      } else {
         ++temp;
      }
   }
   if ( temp ) {
      parse.push_back(temp);
   }

   int size = parse.size();

   int up = N+3, down = 0;
   while( down + 1 < up ) {
      int cur = (up + down)/2;
      //std::cout<<up<<" "<<down<<std::endl;

        stack<int> boo;

      for ( int i = 0 ; i < size ; ++i ) {
         //push current
         boo.push(parse[i]);

         //pop if possible
         while( boo.size() > 2 ){
            int c = boo.top();
            boo.pop();
            int b = boo.top();
            boo.pop();
            int a = boo.top();
            boo.pop();
            
            if ( a == -2 && b == -1 && c >= cur ) {

               if ( boo.empty() || boo.top() == -2 || c == cur) {
                  //do nothing
               } else {      //push back
                  c -= cur;
                  if ( boo.top() == -1 ) {
                     boo.push(c);
                  } else {
                     int temp = boo.top();
                     boo.pop();
                     boo.push(temp+c);
                  }
               }

            } else {
               boo.push(a);
               boo.push(b);
               boo.push(c);
               break;
            }
         }
      }

      if ( boo.empty() ) {
         down = cur;
      } else {
         up = cur;
      }


   }

   return down;
}
int HicCup(string s)
{
   if(ans(s)==0)
   {
        string newstr;
        for(int i=0; i<s.size(); i++)
        {
            newstr.push_back(s[i]);
            if(s[i]=='C')
            {
                newstr.push_back('!');
            }
        }
        if(ans(newstr)==1)
            return 0;
        else
            return -1;
    }
    else
        return ans(s);
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:97:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<s.size(); i++)
                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 7 ms 428 KB Output is correct
4 Correct 32 ms 1096 KB Output is correct
5 Correct 821 ms 20512 KB Output is correct
6 Correct 19 ms 4316 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 828 ms 20568 KB Output is correct
9 Correct 792 ms 20564 KB Output is correct
10 Correct 796 ms 20440 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 5 ms 384 KB Output is correct
3 Correct 7 ms 428 KB Output is correct
4 Correct 32 ms 1096 KB Output is correct
5 Correct 821 ms 20512 KB Output is correct
6 Correct 19 ms 4316 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 828 ms 20568 KB Output is correct
9 Correct 792 ms 20564 KB Output is correct
10 Correct 796 ms 20440 KB Output is correct
11 Correct 583 ms 19216 KB Output is correct
12 Correct 174 ms 9100 KB Output is correct
13 Correct 25 ms 6236 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 36 ms 6196 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 9 ms 888 KB Output is correct
19 Correct 20 ms 4480 KB Output is correct
20 Correct 32 ms 4756 KB Output is correct
21 Correct 22 ms 4352 KB Output is correct
22 Correct 15 ms 4096 KB Output is correct
23 Correct 17 ms 4352 KB Output is correct
24 Correct 58 ms 4860 KB Output is correct
25 Correct 582 ms 19356 KB Output is correct
26 Correct 181 ms 7564 KB Output is correct
27 Correct 17 ms 4352 KB Output is correct
28 Correct 18 ms 4224 KB Output is correct
29 Correct 17 ms 4480 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 380 KB Output is correct
32 Correct 8 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct