結果

問題 No.607 開通777年記念
ユーザー aim_cpo
提出日時 2017-12-07 11:54:03
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 63,400 KB
最終ジャッジ日時 2024-11-29 04:53:55
合計ジャッジ時間 5,360 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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;
            int 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