답안 #828074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828074 2023-08-17T03:40:48 Z tfgs JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 256 KB
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
#define vi vector<ll>
#define vb vector<bool>
#define f0(i,a) for(ll i=0;i<(a);i++)
#define f1(i,a) for(ll i=1;i<(a);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define f first
#define s second
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
#ifdef I_AM_NOOB
#define gg(...) [](const auto&...x){ char c='='; cerr<<#__VA_ARGS__; ((cerr<<exchange(c,',')<<x),...); cerr<<endl; }(__VA_ARGS__);
#else
#define gg(...) 777771449
#endif

constexpr ll INFF = 1e18;
constexpr ll P = 1e9+7;
// constexpr ll P = 998244353;

int main() {
    cin.tie(0) -> ios::sync_with_stdio(0);
    
    ll n, k; while (cin >> n >> k) {
        string s; cin >> s;
        vi p0, p1, p2;
        f0(i, n) {
            if (s[i] == 'J') p0.pb(i);
            if (s[i] == 'O') p1.pb(i);
            if (s[i] == 'I') p2.pb(i);
        }
        if (p0.size() < k || p1.size() < k || p2.size() < k) {
            cout << -1 << endl;
            continue;
        }
        ll l = 0;
        ll r = 0;
        ll ans = INFF;
        queue<ll> q;
        for (ll i = k-1; i < p1.size(); i++) {
            if (p0[l+k-1] > p1[i-k+1]) continue;
            // gg(i);
            while (l+1+k-1 < p0.size() && p0[l+1+k-1] < p1[i-k+1]) ++l;
            if (q.size() > 0) {
                gg(q.front());
                gg(q.size());
            }
            while (q.size() > 0 && p2[q.front()] < p1[i]) {
                gg(q.front(), i);
                q.pop();
            }

            while (r < p2.size() && q.size() < k) {
                if (p2[r] > p1[i]) {
                    q.push(r);
                    gg(r);
                    // gg(r, i, q.size());
                }
                r++;
                if (q.size() == k) r--;
            }

            if (q.size() == k) {
                assert(p0[l+k-1] < p1[i-k+1]);
                gg(p2[r] - p0[l] + 1 - 3*k);
                gg(p0[l] ,p2[r]);
                ans = min(ans, p2[r] - p0[l] + 1 - 3*k);
            }
        }

        cout << (ans == INFF ? -1 : ans) << endl;
    } 
    
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:48:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         if (p0.size() < k || p1.size() < k || p2.size() < k) {
      |             ~~~~~~~~~~^~~
ho_t2.cpp:48:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         if (p0.size() < k || p1.size() < k || p2.size() < k) {
      |                              ~~~~~~~~~~^~~
ho_t2.cpp:48:57: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         if (p0.size() < k || p1.size() < k || p2.size() < k) {
      |                                               ~~~~~~~~~~^~~
ho_t2.cpp:56:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (ll i = k-1; i < p1.size(); i++) {
      |                          ~~^~~~~~~~~~~
ho_t2.cpp:59:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             while (l+1+k-1 < p0.size() && p0[l+1+k-1] < p1[i-k+1]) ++l;
      |                    ~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:61:17: note: in expansion of macro 'gg'
   61 |                 gg(q.front());
      |                 ^~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:62:17: note: in expansion of macro 'gg'
   62 |                 gg(q.size());
      |                 ^~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:65:17: note: in expansion of macro 'gg'
   65 |                 gg(q.front(), i);
      |                 ^~
ho_t2.cpp:69:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             while (r < p2.size() && q.size() < k) {
      |                    ~~^~~~~~~~~~~
ho_t2.cpp:69:46: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   69 |             while (r < p2.size() && q.size() < k) {
      |                                     ~~~~~~~~~^~~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:72:21: note: in expansion of macro 'gg'
   72 |                     gg(r);
      |                     ^~
ho_t2.cpp:76:30: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   76 |                 if (q.size() == k) r--;
      |                     ~~~~~~~~~^~~~
ho_t2.cpp:79:26: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   79 |             if (q.size() == k) {
      |                 ~~~~~~~~~^~~~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:81:17: note: in expansion of macro 'gg'
   81 |                 gg(p2[r] - p0[l] + 1 - 3*k);
      |                 ^~
ho_t2.cpp:30:17: warning: statement has no effect [-Wunused-value]
   30 | #define gg(...) 777771449
      |                 ^~~~~~~~~
ho_t2.cpp:82:17: note: in expansion of macro 'gg'
   82 |                 gg(p0[l] ,p2[r]);
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -