#37443: C++答案


samlin961112@gmail.com (林哲甫)

學校 : 新北市私立南山高級中學
編號 : 220506
來源 : [219.70.213.92]
最後登入時間 :
2024-10-21 22:34:09
c548. Boook 愛鴿子 | From: [219.70.213.92] | 發表日期 : 2023-09-09 15:05

#include <iostream>
#include <cstring>
using namespace std;

int main() {
	cin.sync_with_stdio(false), cin.tie(0);
	int amount, multiple, scores, sums = 0, haveSum[100001], i;
	bool have = false;
	cin >> amount >> multiple;
	memset(haveSum, -1, sizeof(haveSum)), haveSum[0] = 0;
	for (i = 1; i <= amount; i++) {
		cin >> scores;
		sums = (sums + scores % multiple) % multiple;
		if (haveSum[sums] != -1) {
			cout << i - haveSum[sums] << '\n' << haveSum[sums] + 1;
			for (int j = haveSum[sums] + 2; j <= i; j++)
				cout << ' ' << j;
			cout << '\n';
			break;
		}
		haveSum[sums] = i;
	}
	for (i++; i <= amount; i++)
		cin >> scores;
}
 
ZeroJudge Forum