답안 #1087413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087413 2024-09-12T16:04:04 Z vjudge1 Izbori (COCI17_izbori) C++17
16 / 80
3000 ms 7260 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int f(int i,vector<queue<int>>s){
    if(i==n)return 1e9;
    int mx=0,mxi=0;
    int cnt[25]={};
    for(int i=0;i<n;i++){
        cnt[s[i].front()]++;
    }for(int i=1;i<=m;i++){
        if(cnt[i]>mx)mx=cnt[i],mxi=i;
    }if(mxi==k)return 0;
    int ret=f(i+1,s);
    int c=0;
    while(s[i].front()!=k)s[i].pop(),c++;
    ret=min(ret,f(i+1,s)+c+1);
    return ret;
}
int main(){
    cin>>n>>m>>k;
    vector<queue<int>>s(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int x;
            cin>>x;
            s[i].push(x);
        }
    }int mx=0,mxi=0;
    int cnt[25]={};
    for(int i=0;i<n;i++){
        cnt[s[i].front()]++;
    }for(int i=1;i<=m;i++){
        if(cnt[i]>mx)mx=cnt[i],mxi=i;
    }cout<<mxi<<endl;
    cout<<f(0,s)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3069 ms 5212 KB Time limit exceeded
2 Partially correct 1 ms 344 KB Partially correct
3 Partially correct 148 ms 3932 KB Partially correct
4 Execution timed out 3071 ms 4444 KB Time limit exceeded
5 Execution timed out 3067 ms 3676 KB Time limit exceeded
6 Execution timed out 3035 ms 1112 KB Time limit exceeded
7 Execution timed out 3042 ms 2648 KB Time limit exceeded
8 Partially correct 0 ms 344 KB Partially correct
9 Execution timed out 3069 ms 6748 KB Time limit exceeded
10 Partially correct 1 ms 344 KB Partially correct
11 Correct 1 ms 348 KB Output is correct
12 Execution timed out 3095 ms 5656 KB Time limit exceeded
13 Execution timed out 3044 ms 5208 KB Time limit exceeded
14 Execution timed out 3067 ms 4956 KB Time limit exceeded
15 Execution timed out 3040 ms 5208 KB Time limit exceeded
16 Correct 2795 ms 7192 KB Output is correct
17 Execution timed out 3051 ms 5908 KB Time limit exceeded
18 Execution timed out 3058 ms 6236 KB Time limit exceeded
19 Execution timed out 3058 ms 7260 KB Time limit exceeded
20 Execution timed out 3063 ms 7260 KB Time limit exceeded