제출 #545022

#제출 시각아이디문제언어결과실행 시간메모리
545022AsymmetryJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
56 ms12384 KiB
//Autor: Bartłomiej Czarkowski #include <bits/stdc++.h> using namespace std; #ifdef DEBUG template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';} template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';} #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n' #else #define debug(...) {} #endif const int N = 201000; int n, k; int t[N]; int poz[N]; char s[N]; vector<int> v[3]; set<int> S[3]; int main() { scanf("%d%d", &n, &k); scanf("%s", s + 1); for (int i = 1; i <= n; ++i) { if (s[i] == 'J') { t[i] = 0; } else if (s[i] == 'O') { t[i] = 1; } else { t[i] = 2; } v[t[i]].push_back(i); } for (int i = 0; i < 3; ++i) { if ((int)v[i].size() < k) { printf("-1\n"); return 0; } S[i].insert(n + 1 + i); for (int j = 0; j < (int)v[i].size() - k + 1; ++j) { S[i].insert(v[i][j]); poz[v[i][j]] = v[i][j + k - 1]; debug(i, v[i][j], poz[v[i][j]]); } } int odp = 1e9; for (int i = 1; i <= n; ++i) { if (t[i] == 0 && poz[i]) { auto x = S[1].lower_bound(poz[i] + 1); if (*x > n) { continue; } auto y = S[2].lower_bound(poz[*x] + 1); if (*y > n) { continue; } debug(i, *x, poz[*x], *y, poz[*y]); odp = min(odp, poz[*y] - i + 1 - k * 3); } } if (odp > n) { printf("-1\n"); return 0; } printf("%d\n", odp); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%s", s + 1);
      |  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...