Submission #581339

# Submission time Handle Problem Language Result Execution time Memory
581339 2022-06-22T13:40:54 Z Omar_Elgedawy Miners (IOI07_miners) C++14
60 / 100
1166 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define cin(vec)        for(auto& i : vec) cin >> i
#define cout(vec)       for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast            ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b)     for (int i = a; i < b; i++)
#define F               first
#define S               second
#define pb(n)           push_back(n)
#define pf(n)           push_front(n)
#define dci(d)          fixed<<setprecision(d)
#define sp              ' '
#define el              '\n'
#define all(v)          v.begin(),v.end()
#define int             long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=1e5+1,M=1e3+1,Mod=1e9+7;
string s;
int n;
map<char,int>m;
map<pair<int,pair<deque<int>,deque<int>>>,int>dp;
map<pair<int,pair<deque<int>,deque<int>>>,bool>vis;
int rec(int idx,deque<int>msk1,deque<int>msk2){
  if(idx==n)return 0;
  if(vis[make_pair(idx,make_pair(msk1,msk2))]){
    return dp[make_pair(idx,make_pair(msk1,msk2))];
  }
  vis[make_pair(idx,make_pair(msk1,msk2))]=1;
  deque<int>before=msk1,before2=msk2;
  if(msk1.size()==3)
    msk1.pop_front();
  msk1.push_back(m[s[idx]]);
  set<int>cnt;
  for(int i=0;i<msk1.size();i++)cnt.insert(msk1[i]);
  int c1=rec(idx+1,msk1,msk2)+cnt.size();
  cnt.clear();
  if(msk2.size()==3){
    msk2.pop_front();
  }
  msk2.push_back(m[s[idx]]);
  for(int i=0;i<msk2.size();i++)cnt.insert(msk2[i]);
  int c2=rec(idx+1,before,msk2)+cnt.size();
  return dp[make_pair(idx,make_pair(before,before2))]=max(c1,c2);
}
void testcase(int h){
  cin>>n>>s;
  m['M']=0;
  m['B']=1;
  m['F']=2;
  deque<int>q;
  cout<<rec(0,q,q);
}
int32_t main()
{
  // fast
  testcase(1);
  // int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i);
  return 0;
}

Compilation message

miners.cpp: In function 'long long int rec(long long int, std::deque<long long int>, std::deque<long long int>)':
miners.cpp:35:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i=0;i<msk1.size();i++)cnt.insert(msk1[i]);
      |               ~^~~~~~~~~~~~
miners.cpp:42:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i=0;i<msk2.size();i++)cnt.insert(msk2[i]);
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1166 ms 400856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1004 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1067 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 930 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 589 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 420 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -