답안 #1032786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032786 2024-07-24T08:35:59 Z anango Martian DNA (BOI18_dna) C++17
0 / 100
2 ms 600 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1LL<<30;

signed main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    /*#ifdef ONLINE_JUDGE
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    #endif*/ //fast IO
    int n,k,c; cin >> n >> k >> c;
    vector<int> ar(n); for (int i=0; i<n; i++) cin >> ar[i];
    vector<int> freq(k,0); 
    vector<int> req(k,0);
    for (int i=0; i<c; i++) {
        int a,b; cin >> a >> b;
        req[a] = b;
    }
    int unsatisfied = 0;
    for (int i=0; i<k; i++) unsatisfied+=req[i]>0;
    int r = -1;
    int ans = INF;
    for (int l=0; l<n; l++) {
        while (unsatisfied>0 && r<n-1) {
            r++;
            freq[ar[r]]++;
            unsatisfied-=freq[ar[r]]==req[ar[r]];
        }
        //cout << l <<" " << r <<" " << unsatisfied << endl;

        if (unsatisfied==0) {
            ans=min(ans,r-l+1);
        }
        unsatisfied+=freq[ar[l]]==req[ar[l]];
        freq[ar[l]]--;

    }
    if (ans<INF) cout << ans << endl;
    else cout << "impossible" << endl;
    
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -