Submission #1417234


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
vector<ll> V;
ll mo=1000000007;
ll memo[105][105];

ll hoge(int L,int R) {
	int i;
	
	if(memo[L][R]>=-1) return memo[L][R];
	
	for(i=R-3;i>=L+1;i--) {
		if(V[i]==-2 && V[i+1]==-2) {
			ll a=hoge(L,i);
			ll b=hoge(i+2,R);
			if(a>=0 && b>=0) {
				if(b>=60) a=0;
				return memo[L][R]=a>>b;
			}
		}
	}
	
	if(V[L]==-1 && V[R-1]==-2){
		ll a=hoge(L+1,R-1);
		if(a>=0) return memo[L][R]=a*a%mo;
	}
	if(V[L]>=0 && L+1==R) return memo[L][R]=V[L];
	return memo[L][R]=-1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	while(1) {
		getline(cin,S);
		if(S[0]=='#') break;
		V.clear();
		FORR(c,S) {
			if(c=='S') V.push_back(-1);
			if(c=='>') V.push_back(-2);
			if(c>='0' && c<='9') {
				if(V.empty()||V.back()<0) V.push_back(0);
				V.back()=V.back()*10+c-'0';
			}
		}
		FOR(x,V.size()+1) FOR(y,V.size()+1) memo[x][y]=-2;
		cout<<hoge(0,V.size())<<endl;
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Submission Info

Submission Time
Task F - Shipura
User kmjp
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1606 Byte
Status RE
Exec Time 111 ms
Memory 1656 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
RE × 1
Set Name Test Cases
all Merged
Case Name Status Exec Time Memory
Merged RE 111 ms 1656 KB