답안 #880489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880489 2023-11-29T14:12:41 Z cpptowin JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
using namespace std;
string s;
int ans = inf;
int n,k;
main()
{
    #define name "TASK"
    if(fopen(name".inp","r"))
    {
       freopen(name".inp","r",stdin);
       freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> k;
    cin >> s;
    fo(i,0,(int)s.size() - 1)
    {
        bool ok = 0;
        int cnt1 = 0,cnt2 = 0,cnt3 = 0,now = 0;
        fo(j,i,(int)s.size() - 1)
        {
            if(cnt1 < k)
            {
                if(s[j] == 'J') cnt1++;
                else now++;
            }
            else if(cnt1 == k and cnt2 < k)
            {
                if(s[j] == 'O') cnt2++;
                else now++;
            }
            else if(cnt1 == k and cnt2 == k and cnt3 < k)
            {
                if(s[j] == 'I') cnt3++;
                else now++;
            }
            else if(cnt1 == k and cnt2 == k and cnt3 == k)
            {
                ok = 1;
                break;
            }
        }
        if(ok) ans = min(ans,now);
    }
    cout << (ans == inf ? -1 : ans);
}

Compilation message

ho_t2.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:31:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -