40pts AC #2 #3 求助
查看原帖
40pts AC #2 #3 求助
424089
LuoTianyi_Official楼主2022/9/10 00:16

错的三个点都显示在有解的情况下输出 NIE

#include <iostream>
using namespace std;
int a[1000005], prel[2000005], prer[2000005];
int main() {
    int n, m, summ=0, e=-1, epos, o=-1, opos, x, y, t;
    cin >> n >> m; getchar();
    for (int i=1; i<=n; i++) {
        summ += a[i] = (getchar() == 'T') + 1;
        if (summ % 2) {o = summ; opos = i; continue;}
        e = summ; epos = i;
    }
    x = 1; y = epos; summ = e;
    while (summ) {
        prel[summ] = x; prer[summ] = y; t = x;
        if (a[x] == 2 || a[y] == 1) x++;
        if (a[t] == 1) y--;
        summ -= 2;
    }
    x = 1; y = opos; summ = o;
    while (summ + 1) {
        prel[summ] = x; prer[summ] = y; t = x;
        if (a[x] == 2 || a[y] == 1) x++;
        if (a[t] == 1) y--;
        summ -= 2; 
    }
    for (int i=1; i<=m; i++) {
        cin >> x; if ((x & 1) ? x > o : x > e) {cout << "NIE" << endl; continue;}
        cout << prel[x] << ' ' << prer[x] << endl;
    }
    return 0;
}

由于时间久远,我看不懂自己写的代码了。但是它看起来也不像任何一篇题解。

2022/9/10 00:16
加载中...