Submission #118324

#TimeUsernameProblemLanguageResultExecution timeMemory
118324popovicirobertLollipop (POI11_liz)C++14
16 / 100
810 ms35420 KiB
#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]; if(pos != -1) { for(i = pos; i <= n; i++) { int cur = sp[i] - sp[pos - 1]; sums[cur & 1].push_back(cur); } } 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 << " " << r - 1 << "\n"; continue; } } cout << "NIE\n"; } //cin.close(); //cout.close(); return 0; }

Compilation message (stderr)

liz.cpp: In function 'int main()':
liz.cpp:36:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> m >> str + 1;
                      ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...