結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー tentententen
提出日時 2023-07-06 13:06:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 2,148 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 58,792 KB
最終ジャッジ日時 2023-09-27 14:16:35
合計ジャッジ時間 15,862 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,416 KB
testcase_01 AC 44 ms
49,444 KB
testcase_02 AC 44 ms
49,284 KB
testcase_03 AC 44 ms
49,408 KB
testcase_04 AC 45 ms
49,840 KB
testcase_05 AC 44 ms
49,384 KB
testcase_06 AC 45 ms
49,432 KB
testcase_07 AC 392 ms
58,540 KB
testcase_08 AC 399 ms
58,496 KB
testcase_09 AC 385 ms
58,032 KB
testcase_10 AC 386 ms
58,508 KB
testcase_11 AC 388 ms
58,244 KB
testcase_12 AC 299 ms
58,184 KB
testcase_13 AC 301 ms
58,304 KB
testcase_14 AC 293 ms
58,792 KB
testcase_15 AC 399 ms
58,044 KB
testcase_16 AC 399 ms
58,220 KB
testcase_17 AC 399 ms
58,480 KB
testcase_18 AC 392 ms
58,732 KB
testcase_19 AC 399 ms
58,200 KB
testcase_20 AC 402 ms
58,288 KB
testcase_21 AC 400 ms
58,312 KB
testcase_22 AC 401 ms
58,128 KB
testcase_23 AC 278 ms
57,984 KB
testcase_24 AC 321 ms
58,248 KB
testcase_25 AC 330 ms
58,332 KB
testcase_26 AC 228 ms
56,956 KB
testcase_27 AC 149 ms
54,864 KB
testcase_28 AC 357 ms
58,700 KB
testcase_29 AC 355 ms
58,628 KB
testcase_30 AC 169 ms
56,852 KB
testcase_31 AC 216 ms
57,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        while (k-- > 0) {
            int r = sc.nextInt();
            int c = sc.nextInt();
            int v = sc.nextInt();
            long current = (long)r * w;
            current += MOD - getValue(w - c, r);
            current %= MOD;
            current += MOD - getValue(c - 1, r);
            current %= MOD;
            ans += current * v % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long getValue(long width, long height) {
        return (width + Math.max(width - height + 1, 1)) * Math.min(height, width) / 2 % MOD;
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0