Submission #76930

# Submission time Handle Problem Language Result Execution time Memory
76930 2018-09-19T14:27:07 Z farukkastamonuda Miners (IOI07_miners) C++14
100 / 100
304 ms 113560 KB
#include <bits/stdc++.h>
#define li 100005
#define inf 1000000000
using namespace std;
int n,dp[li][4][4][4][4];
char s[li];
int solve(int a,int b,int c){
    int tp[5]={};
    tp[a]++;
    tp[b]++;
    tp[c]++;
    int cev=0;
    for(int i=1;i<=3;i++){
        if(tp[i]>=1) cev++;
    }
    return cev;
}
int dfs(int node,int pre1,int pre2,int on1,int on2){
    int cevap=-inf;
    if(node==n+1) return 0;
    if(~dp[node][pre1][pre2][on1][on2]) return dp[node][pre1][pre2][on1][on2];
    int tut1=0;
    if(s[node]=='B') tut1=1;
    if(s[node]=='M') tut1=2;
    if(s[node]=='F') tut1=3;
    cevap=max(cevap,dfs(node+1,tut1,pre1,on1,on2)+solve(tut1,pre1,pre2));
    cevap=max(cevap,dfs(node+1,pre1,pre2,tut1,on1)+solve(tut1,on1,on2));
    return dp[node][pre1][pre2][on1][on2]=cevap;
}
int main(){
    memset(dp,-1,sizeof(dp));
    scanf("%d %s",&n,s+1);
    int ty=dfs(1,0,0,0,0);
    printf("%d\n",ty);

    return 0;
}

Compilation message

miners.cpp: In function 'int main()':
miners.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %s",&n,s+1);
     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 94 ms 100600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 100736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 100736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 100736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 100736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 100736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 100972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 101472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 102044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 104044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 110432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 113560 KB Output is correct