AcWing 3175. 建议减弱数据 java过不去
原题链接
简单
作者:
季之秋
,
2021-04-02 13:59:45
,
所有人可见
,
阅读 465
import java.io.*;
import java.util.*;
public class Main{
static int N = 1000010;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int k = Integer.parseInt(br.readLine());
String s = br.readLine();
s += ".";
List<Integer> Alice = new ArrayList();
List<Integer> Bob = new ArrayList();
StringBuilder tem = new StringBuilder();
for(int i=0; i<s.length(); i++){
if(! (Character.isLetter( s.charAt(i)) ) ){
String str = tem.toString();
if(str.equals("Alice")) Alice.add( i-tem.length() );
if(str.equals("Bob")) Bob.add( i-tem.length() );
tem.delete(0,tem.length());
}else{
tem.append(s.charAt(i));
}
}
long res = 0;
int n = Alice.size();
int m = Bob.size();
int l = 0,r = m-1 ;
for(int i=0; i<n; i++){
while(l<m && Bob.get(l) < Alice.get(i) - k -3 ) l++;
r = l;
while(r<m && Bob.get(r) <= Alice.get(i) + 5 +k ) r++;
if(r-l > 0) res += r-l;
}
System.out.println(res);
}
}
Acwing过不去,而且蓝桥官网数据有问题,代码0分