QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#363160#8509. Expanding STACKS!ucup-team3113#RE 1ms3816kbC++201.6kb2024-03-23 18:58:552024-03-23 18:58:55

Judging History

你现在查看的是最新测评结果

  • [2024-03-23 18:58:55]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3816kb
  • [2024-03-23 18:58:55]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

using namespace std;

const int inf = 1e18;

void p(auto A){
	for(auto e : A)cout << e << ' ';
	cout << '\n';
}

void solve(){
	int n; cin >> n;
	vector<int>A(2*n);
	for(int i = 0; i< 2*n; i++)cin >> A[i];
	vector<int>out(n+1);
	for(int i = 0; i< 2*n; i++)if(A[i] < 0)out[abs(A[i])] = i;
	vector<int>G, S;
	G.pb(2*n+5);
	S.pb(2*n+5);
	vector<char>ans(n+1);
	for(int i = 0; i< 2*n; i++){
		if(A[i] < 0){
			assert(G.back() == i || S.back() == i);
			if(G.back() == i)G.pop_back();
			if(S.back() == i)S.pop_back();
		}else{
			int t = out[A[i]];
			if( t > G.back() && t > S.back()){
				cout << '*';
				return;
			}
			if(t < G.back() && t < S.back()){
				if(G.back() > S.back()){
					ans[A[i]] = 'S';
					S.pb(t);
				}else{
					ans[A[i]] = 'G';
					G.pb(t);
				}
			}else{
				if(G.back() < S.back()){
					ans[A[i]] = 'S';
					S.pb(t);
				}else{
					ans[A[i]] = 'G';
					G.pb(t);
				}
			}
		}
	}
	vector<int> s1, s2;
	for(auto e : A){
		if(e< 0){
			if(s1.back() == -e)s1.pop_back();
			else if(s2.back() == -e)s2.pop_back();
			else assert(false);
		}else{
			if(ans[e] == 'G')s1.pb(e);
			else s2.pb(e);
		}
	}
		
	for(int i = 1; i<= n; i++)cout << ans[i];
}
		

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t = 1;
	//cin >> t;
	while(t--)solve();
}


//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

GGGGGGGGGG

result:

ok correct

Test #5:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

GGGGGGGGGS

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

42
+26 -26 +12 +8 -12 -8 +30 +5 +22 +3 -3 +2 -30 +10 -10 -2 -22 +23 +39 -39 +17 -17 -23 +38 +24 -24 +27 +29 -29 -27 -38 -5 +37 -37 +21 +16 +28 -28 +6 +40 +14 +19 -19 -14 +11 +35 -35 -11 +4 +25 -25 -4 -40 -6 +13 +20 +1 -1 +33 +34 +7 -7 -34 +41 -41 +36 +31 -31 -36 +42 +32 -32 +15 +18 -18 -15 +9 -9 -42...

output:

GSGGSGGSGSGGGGGGSGGGGSSSGGSGSGGGGGGGGSSGGG

result:

ok correct

Test #7:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

42
+40 +18 +42 +2 +1 +21 +33 -2 +8 -33 -8 +14 -40 +34 +30 +31 -31 -30 +5 -5 +4 -34 +13 +3 -13 -3 -4 +28 -28 +17 -17 +35 +10 -10 +16 +39 +36 +37 -37 -36 -39 +25 +6 +41 -41 +20 +12 +32 -32 -25 -12 -16 -35 +38 -20 -38 -14 +15 -15 +9 +26 +23 -21 -1 +7 -23 +22 +24 -7 -24 -42 -18 -22 -26 -9 -6 +27 +29 -29...

output:

SGSGSGSGGSGGGSSSSSGGSGGGSGGSGSSSSSSSSSSGSS

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

42
+29 +6 +7 +2 -7 -2 +23 -23 -6 -29 +19 -19 +16 +8 -16 -8 +32 -32 +3 +37 +17 -17 -37 -3 +22 -22 +18 +1 +40 +36 -1 -36 -40 -18 +9 -9 +30 +25 -25 +14 +39 +5 +20 -5 +12 -39 +28 +10 -14 +24 -24 +35 +15 -15 +41 -30 +33 -33 -41 -35 -10 -28 -12 +21 +38 -38 -21 +11 +13 -13 +4 +42 +27 +34 -34 +31 -31 +26 -2...

output:

GSGSGGGSGSSSSGGGGGGSSGGGGSSSGGSGSSSSGSGSSS

result:

ok correct

Test #9:

score: -100
Runtime Error

input:

100
+39 -39 +4 +71 -71 +53 -53 +46 -46 -4 +91 -91 +97 -97 +6 -6 +54 -54 +76 +35 -35 +50 +89 -89 +98 -50 -76 -98 +34 +55 +95 -34 +36 -36 +73 -95 -55 +18 +47 +20 +30 +33 -30 -33 +80 -73 +51 -51 -80 -20 +69 +77 -69 +85 +62 +84 -84 -77 +48 +49 -49 +1 -1 -48 +19 -19 -62 -85 +41 +16 -16 -41 +63 +2 -2 +65 ...

output:


result: