結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー tentententen
提出日時 2023-02-28 13:01:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 2,101 bytes
コンパイル時間 4,429 ms
コンパイル使用メモリ 93,916 KB
実行使用メモリ 44,160 KB
最終ジャッジ日時 2023-10-13 19:37:47
合計ジャッジ時間 17,365 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
33,188 KB
testcase_01 AC 38 ms
33,556 KB
testcase_02 AC 38 ms
33,252 KB
testcase_03 AC 39 ms
33,472 KB
testcase_04 AC 40 ms
33,356 KB
testcase_05 AC 39 ms
33,216 KB
testcase_06 AC 40 ms
33,256 KB
testcase_07 AC 410 ms
43,044 KB
testcase_08 AC 410 ms
43,492 KB
testcase_09 AC 402 ms
43,212 KB
testcase_10 AC 402 ms
44,160 KB
testcase_11 AC 395 ms
42,928 KB
testcase_12 AC 308 ms
43,424 KB
testcase_13 AC 305 ms
42,748 KB
testcase_14 AC 297 ms
42,784 KB
testcase_15 AC 426 ms
43,092 KB
testcase_16 AC 424 ms
43,164 KB
testcase_17 AC 417 ms
43,224 KB
testcase_18 AC 417 ms
43,368 KB
testcase_19 AC 428 ms
43,576 KB
testcase_20 AC 415 ms
43,172 KB
testcase_21 AC 406 ms
43,152 KB
testcase_22 AC 416 ms
43,268 KB
testcase_23 AC 277 ms
42,728 KB
testcase_24 AC 326 ms
43,232 KB
testcase_25 AC 330 ms
43,152 KB
testcase_26 AC 230 ms
42,720 KB
testcase_27 AC 151 ms
40,724 KB
testcase_28 AC 372 ms
42,800 KB
testcase_29 AC 370 ms
42,876 KB
testcase_30 AC 172 ms
41,616 KB
testcase_31 AC 228 ms
42,608 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 n = sc.nextInt();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            long v = sc.nextInt();
            long left = Math.min(x, y);
            long count = MOD - x;
            count += left * (x + x - left + 1) / 2 % MOD;
            count %= MOD;
            long right = Math.min(x, w - y + 1);
            count += right * (x + x - right + 1) / 2 % MOD;
            count %= MOD;
            ans += count * v % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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