求助!60分,五个TLE(7, 8, 9, 10, 12)用的Java
查看原帖
求助!60分,五个TLE(7, 8, 9, 10, 12)用的Java
767344
DuXinran楼主2022/9/22 15:00
import java.util.Scanner;
import java.util.Arrays;
//import java.util.ArrayList;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
//		Scanner s = new Scanner(System.in);
		InputReader s = new InputReader(); 
		int N = s.nextInt();
		int[] presum = new int[N+1];
		presum[0] = 0;
		int count = 0;
		for (int i = 0; i<N; i++) {
			presum[i+1] = presum[i]+s.nextInt();
		}
		for (int i = 0; i<N; i++) {
			for (int j = i+1; j<N+1; j++) {
				if ((presum[j]-presum[i])%7 == 0 && j-i>count) {
					count = j-i;
				}
			}
		}
		System.out.print(count);
	}
}

class InputReader {
    StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public int nextInt() throws Exception{
        st.nextToken();
        return (int)st.nval;
    }
    public long nextLong() throws Exception{
        st.nextToken();
        return (long)st.nval;
    }
}

2022/9/22 15:00
加载中...