rt,以下是我的代码:
int work_FR(){
unordered_map<int,int> tmp;
int cnt=0, ans=0;
for(int i=0;i<srr.size();i++){
int a=srr[i].first, b=srr[i].second;
tmp[b]++;
if(tmp[b]==1 && check.find(b)!=check.end()) cnt++;
}
int j=srr.size()-1;
for(int i=c;i>=1;i--){
if(crr[i]=='F'){
tmp[srr[j].second]--;
tmp[srr[j].second+1]++;
if(tmp[srr[j].second+1]==1 && check.find(srr[j].second+1)!=check.end()) cnt++;
if(tmp[srr[j].second]==0 && check.find(srr[j].second)!=check.end()) cnt--;
j--;
}
if(crr[i]=='F'){
tmp[step[i-1]]++;
if(tmp[step[i-1]]==1 && check.find(step[i-1])!=check.end()){
FR[i]=cnt-1;
}else{
FR[i]=cnt;
}
tmp[step[i-1]]--;
ans=max(ans,FR[i]);
}
}
return ans;
}
int work_FL(){
unordered_map<int,int> tmp;
int cnt=0, ans=0;
for(int i=0;i<srr.size();i++){
int a=srr[i].first, b=srr[i].second;
tmp[b]++;
if(tmp[b]==1 && check.find(b)!=check.end()) cnt++;
}
int j=srr.size()-1;
for(int i=c;i>=1;i--){
if(crr[i]=='F'){
tmp[srr[j].second]--;
tmp[srr[j].second-1]++;
if(tmp[srr[j].second-1]==1 && check.find(srr[j].second-1)!=check.end()) cnt++;
if(tmp[srr[j].second]==0 && check.find(srr[j].second)!=check.end()) cnt--;
j--;
}
if(crr[i]=='F'){
tmp[step[i-1]]++;
if(tmp[step[i-1]]==1 && check.find(step[i-1])!=check.end()){
FL[i]=cnt-1;
}else{
FL[i]=cnt;
}
tmp[step[i-1]]--;
ans=max(ans,FL[i]);
}
}
return ans;
}
很显然,tmp[step[i-1]]==1 的 ==1 应该改为 ==2,但是他过了 Record
hack.in
4 5
4 8 1 6
RRFLF
hack.out
1
我的错误输出:
0