QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499882#8509. Expanding STACKS!hhhhyfWA 0ms3592kbC++202.1kb2024-07-31 19:55:182024-07-31 19:55:18

Judging History

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

  • [2024-07-31 19:55:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-07-31 19:55:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
void print() { cout << '\n'; }
template <typename T, typename...Args>
void print(T t, Args...args) { cout << t << ' '; print(args...); }
using ll = long long;
const int N = 1e6 + 1, inf = 1e9;

int dir[4][2] = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1}
};

template <typename T> bool chmax(T &x, T y) { if (y > x) { x = y; return true; } return false; }
template <typename T> bool chmin(T &x, T y) { if (y < x) { x = y; return true; } return false; }

template <typename T = int>
vector<T> readVector(int n) {
    vector<T> a(n);
    for(T &x: a) cin >> x;
    return a;
} 

void solve () {
    int n;
    cin >> n;
    
    vector<array<int, 2>> a(2 * n);
    vector<int> pos(n);
    
    for (int i = 0; i < 2 * n; i ++) {
        char c;
        int x;
        cin >> c >> x;
        x --;
        if (c == '+') {
            a[i] = {0, x};
        } else {
            a[i] = {1, x};
            pos[x] = i;
        }
    }
    
    stack<int> stk[2];
    string s;
    for (auto& [t, i]: a) {
        if (t == 0) {
            if (stk[0].size() && pos[i] < pos[stk[0].top()]) {
                stk[0].push(i);
            } else if (stk[1].size() && pos[i] < pos[stk[1].top()]) {
                stk[1].push(i);
            } else if (stk[0].empty()) {
                stk[0].push(i);
            } else if (stk[1].empty()) {
                stk[1].push(i);
            } else {
                cout << '*';
                return;
            }
        } else {
            if (stk[0].size() && stk[0].top() == i) {
                stk[0].pop();
                s += 'G';
            } else if (stk[1].size() && stk[1].top() == i) {
                stk[1].pop();
                s += 'S';
            } else {
                cout << '*';
                return;
            }
        }
    }
    cout << s;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int t = 1; 
	//cin >> t;
	while(t --) {
	    solve();
	}

	return 0;
}

详细

Test #1:

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

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

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

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

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

input:

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

output:

*

result:

ok correct

Test #4:

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

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: -100
Wrong Answer
time: 0ms
memory: 3592kb

input:

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

output:

GGSGGGGGGG

result:

wrong answer client leaving is not the top of its stack