結果

問題 No.607 開通777年記念
ユーザー aim_cpoaim_cpo
提出日時 2017-12-07 11:57:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,839 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 78,084 KB
実行使用メモリ 52,552 KB
最終ジャッジ日時 2024-05-06 19:15:59
合計ジャッジ時間 4,558 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,172 KB
testcase_01 AC 120 ms
41,384 KB
testcase_02 AC 116 ms
41,408 KB
testcase_03 AC 99 ms
40,328 KB
testcase_04 AC 100 ms
40,300 KB
testcase_05 AC 104 ms
40,164 KB
testcase_06 AC 101 ms
40,192 KB
testcase_07 AC 423 ms
49,784 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 161 ms
42,780 KB
testcase_11 AC 176 ms
52,524 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            long a[][] = new long[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = in.nextLong();
                    if (i != 0) {
                        a[i][j] += a[i - 1][j];
                    }
                }
                if (ok(a, n, i)) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

        private boolean ok(long[][] a, int n, int i) {
            int l = 0;
            long sum = 0;
            for (int r = 0; r < n; r++) {
                if (sum == 777) return true;
                if (a[i][r] + sum <= 777) {
                    sum += a[i][r];
                } else {
                    while (sum + a[i][r] > 777) {
                        sum -= a[i][l];
                        l++;
                    }
                    sum += a[i][r];
                    if (l > r) r++;
                }
            }
            if (sum == 777) return true;
            return false;
        }

    }
}

0