Submission #1695595


Source Code Expand

//2017-10-19
//miaomiao
//Island loops deep york
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (200000+5)

char s[N];
int lst[N], nxt[N];

int main(){
	scanf("%s", s+1);

	int n = strlen(s+1);
	For(i, 1, n) lst[i] = i-1, nxt[i] = i+1;
	nxt[n] = 0;
	
	int st = -1;
	For(i, 1, n-1) if(s[i] == 'S' && s[i+1] == 'T'){
		st = i; break;
	}
	
	int ans = n, p;
	while(st != -1){
		ans -= 2;
		if(!lst[st] && !nxt[nxt[st]]) break;

		if(lst[st]) p = lst[st], nxt[p] = nxt[nxt[st]], lst[nxt[nxt[st]]] = p;
		else p = nxt[nxt[st]], lst[p] = 0;

		while(nxt[p] && (s[p]!='S' || s[nxt[p]]!='T')) p = nxt[p];
		st = nxt[p]? p: -1;
	}

	printf("%d\n", ans);

	return 0;
}

Submission Info

Submission Time
Task A - STring
User miaomiao
Language C++14 (GCC 5.4.1)
Score 300
Code Size 864 Byte
Status AC
Exec Time 4 ms
Memory 2048 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:21:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s+1);
                  ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 3
AC × 9
AC × 13
Set Name Test Cases
Sample example0, example1, example2
Subtask1 example0, example1, example2, sub_corner0, sub_corner1, sub_corner2, sub_rand0, handmade0, handmade1
All corner0, corner1, corner2, example0, example1, example2, handmade0, handmade1, maxrand0, sub_corner0, sub_corner1, sub_corner2, sub_rand0
Case Name Status Exec Time Memory
corner0 AC 3 ms 2048 KB
corner1 AC 3 ms 2048 KB
corner2 AC 4 ms 2048 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
handmade0 AC 1 ms 256 KB
handmade1 AC 1 ms 256 KB
maxrand0 AC 4 ms 2048 KB
sub_corner0 AC 1 ms 256 KB
sub_corner1 AC 1 ms 256 KB
sub_corner2 AC 1 ms 256 KB
sub_rand0 AC 1 ms 256 KB