結果
問題 | No.1535 五七五 |
ユーザー |
![]() |
提出日時 | 2021-06-07 12:14:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 1,776 bytes |
コンパイル時間 | 1,991 ms |
コンパイル使用メモリ | 78,152 KB |
実行使用メモリ | 64,812 KB |
最終ジャッジ日時 | 2024-11-24 14:41:38 |
合計ジャッジ時間 | 7,028 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int[] sums = new int[n + 1]; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1]; sums[i] += sc.next().length(); } int x = n; int y = n; int z = n; int ans = 0; for (int i = n; i >= 0 && x >= 0 && y >= 0 && z >= 0; i--) { while (z >= 0 && sums[i] - sums[z] < c) { z--; } if (z < 0 || sums[i] - sums[z] > c) { continue; } while (y >= 0 && sums[z] - sums[y] < b) { y--; } if (y < 0 || sums[z] - sums[y] > b) { continue; } while (x >= 0 && sums[y] - sums[x] < a) { x--; } if (x < 0 || sums[y] - sums[x] > a) { continue; } ans++; } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }