QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368332#8509. Expanding STACKS!ucup-team134#WA 1ms3800kbC++171.3kb2024-03-27 00:49:442024-03-27 00:49:45

Judging History

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

  • [2024-03-27 00:49:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3800kb
  • [2024-03-27 00:49:44]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> in(n,-1),out(n);
	vector<int> ord;
	for(int i=0;i<2*n;i++){
		string s;
		cin >> s;
		s=s.substr(1);
		int x=stoi(s)-1;
		if(in[x]==-1){
			in[x]=i;
			ord.pb(x);
		}
		else{
			out[x]=i;
		}
	}
	vector<int> ans(n);
	vector<int> a,b;
	for(auto i:ord){
		int tr=in[i];
		while(sz(a)&&a.back()<tr)a.pop_back();
		while(sz(b)&&b.back()<tr)b.pop_back();
		//printf("%i %i\n",in[i],out[i]);
		bool canA=sz(a)==0||a.back()>out[i];
		bool canB=sz(b)==0||b.back()>out[i];
		//cout << i << " " << canA << " " << canB << endl;
		if(!canA&&!canB){
			printf("*\n");
			return 0;
		}
		if(canA&&canB){
			if(sz(b)==0||(sz(a)!=0&&a.back()<b.back())){
				a.pb(out[i]);
				ans[i]=0;
			}
			else{
				b.pb(out[i]);
				ans[i]=1;
			}
		}
		if(canA){
			a.pb(out[i]);
			ans[i]=0;
		}
		else{
			b.pb(out[i]);
			ans[i]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i])printf("G");
		else printf("S");
	}
	printf("\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
+2 +1 -1 -2

output:

SS

result:

ok correct

Test #2:

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

input:

2
+1 +2 -1 -2

output:

SG

result:

ok correct

Test #3:

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

input:

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

output:

*

result:

ok correct

Test #4:

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

input:

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

output:

SSSSSSSSSS

result:

ok correct

Test #5:

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

input:

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

output:

SSSSSSSSSG

result:

ok correct

Test #6:

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

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:

SGSSGSSGSSSSSSSSSSSSSGSSSSSSSSSSSSSSSSSSSS

result:

ok correct

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3588kb

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:

*

result:

wrong answer team and jury output doesn't agree on whether there's an assignment