結果

問題 No.988 N×Mマス計算(総和)
コンテスト
ユーザー kiefer_von_maus
提出日時 2020-02-28 23:50:27
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 688 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 933 ms
コンパイル使用メモリ 183,976 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-27 19:00:28
合計ジャッジ時間 1,664 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, m, k;
	cin >> n >> m >> k;
	char op;
	cin >> op;
	long long ans = 0;
	long long a[n], b[m];
	for(int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long int c = 0, d = 0;

	if(op == '+') {
		for(int i = 0; i < n; i++) {
			c += a[i];
			c = c % k;
		}
		for(int i = 0; i < m; i++) {
			d += b[i];
			d = d % k;
		}
	    ans = (c * m + d * n) % k;
	}
	if(op == '*') {
		for(int i = 0; i < n; i++) {
			c += a[i];
			c = c % k;
		}
		for(int i = 0; i < m; i++) {
			ans += c * b[i];
			ans = ans % k;
		}
	}
	cout << ans << endl;
}
0