답안 #118329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118329 2019-06-18T16:23:17 Z popovicirobert Lollipop (POI11_liz) C++14
100 / 100
719 ms 36488 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = (int) 1e6;

int where[2 * MAXN + 1], sp[MAXN + 1];
char str[MAXN + 1];
int n;

inline int find(int val) {
    int res = 0;
    for(int step = 1 << 19; step; step >>= 1) {
        if(res + step <= n && sp[res + step] <= val) {
            res += step;
        }
    }

    if(sp[res] != val) res = -1;

    return res;
}

int main() {
    //ifstream cin("B.in");
    //ofstream cout("B.out");
    int i, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> str + 1;

    int pos = -1;
    for(i = 1; i <= n; i++) {
        sp[i] = sp[i - 1];

        if(str[i] == 'W') {
            if(pos == -1) {
                pos = i;
            }
            sp[i]++;
        }
        else {
            sp[i] += 2;
        }

        where[sp[i]] = i;
    }

    vector <int> sums[2], ind[2];
    if(pos != -1) {
        for(i = pos; i <= n; i++) {
            int cur = sp[i] - sp[pos - 1];
            sums[cur & 1].push_back(cur);
            ind[cur & 1].push_back(i);
        }
    }

    while(m--) {
        int x;
        cin >> x;

        if(sp[n] < x) {
            cout << "NIE\n";
            continue;
        }

        if(where[x] > 0) {
            cout << 1 << " " << where[x] << "\n";
            continue;
        }

        if(pos != -1) {
            int r = find(sp[pos] + x);
            if(r != -1) {
                cout << pos + 1 << " " << r << "\n";
                continue;
            }

            r = find(sp[pos - 1] + x);
            if(r != -1) {
                cout << pos << " " << r << "\n";
                continue;
            }

            r = upper_bound(sums[x & 1].begin(), sums[x & 1].end(), x) - sums[x & 1].begin();

            if(sums[x & 1].size() && r > 0 && sums[x & 1][r - 1] + 2 * (pos - 1) >= x) {
                cout << pos - (x - sums[x & 1][r - 1]) / 2 << " " << ind[x & 1][r - 1] << "\n";
                continue;
            }
        }


        cout << "NIE\n";

    }

    //cin.close();
    //cout.close();
    return 0;
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:36:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> m >> str + 1;
                      ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1124 KB Output is correct
2 Correct 9 ms 1176 KB Output is correct
3 Correct 34 ms 2312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2512 KB Output is correct
2 Correct 142 ms 5104 KB Output is correct
3 Correct 61 ms 3304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2804 KB Output is correct
2 Correct 23 ms 2392 KB Output is correct
3 Correct 68 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 5220 KB Output is correct
2 Correct 96 ms 5116 KB Output is correct
3 Correct 156 ms 10088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 13172 KB Output is correct
2 Correct 290 ms 12360 KB Output is correct
3 Correct 413 ms 20480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 306 ms 15684 KB Output is correct
2 Correct 354 ms 16148 KB Output is correct
3 Correct 409 ms 18996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 719 ms 29384 KB Output is correct
2 Correct 476 ms 26720 KB Output is correct
3 Correct 578 ms 33564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 31296 KB Output is correct
2 Correct 629 ms 36488 KB Output is correct
3 Correct 369 ms 35796 KB Output is correct