답안 #22927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22927 2017-04-30T13:21:24 Z exqt 다항식 계산 (KRIII5P_2) C++14
7 / 7
586 ms 5928 KB
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, p; cin >> n >> p;
	vector<int> a(max(n+1, p+1), 0);
	for(int i=n; i>=0; i--) a[0] = 0;
	for(int i=n; i>=0; i--) cin >> a[i];
	for(int i=n; i>=0; i--) a[i] %= p;
	
	int c = a[0];
 
	for(int i=p-1; i<=n; i++)
	{
		a[i%(p-1)] = (a[i%(p-1)] + a[i]) % p;
	}
 
	for(int i=0; i<p; i++)
	{
		if(i == 0) 
		{
			cout << c << endl;
			continue;
		}
 
		int r = 0;
		int t = 1;
		for(int j=0; j<p-1; j++)
		{
			r = (r + 1LL * t * a[j]) % p; 
			t = (t * i) % p;
		}
 
		cout << r << endl;
	}
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 19 ms 2020 KB Output is correct
7 Correct 26 ms 2020 KB Output is correct
8 Correct 26 ms 2020 KB Output is correct
9 Correct 16 ms 2020 KB Output is correct
10 Correct 16 ms 2020 KB Output is correct
11 Correct 9 ms 2020 KB Output is correct
12 Correct 19 ms 2020 KB Output is correct
13 Correct 6 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 6 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 19 ms 2020 KB Output is correct
7 Correct 26 ms 2020 KB Output is correct
8 Correct 26 ms 2020 KB Output is correct
9 Correct 16 ms 2020 KB Output is correct
10 Correct 16 ms 2020 KB Output is correct
11 Correct 9 ms 2020 KB Output is correct
12 Correct 19 ms 2020 KB Output is correct
13 Correct 6 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 6 ms 2020 KB Output is correct
16 Correct 486 ms 5928 KB Output is correct
17 Correct 509 ms 5928 KB Output is correct
18 Correct 496 ms 5928 KB Output is correct
19 Correct 523 ms 5928 KB Output is correct
20 Correct 469 ms 5928 KB Output is correct
21 Correct 516 ms 5928 KB Output is correct
22 Correct 513 ms 5928 KB Output is correct
23 Correct 516 ms 5928 KB Output is correct
24 Correct 473 ms 5928 KB Output is correct
25 Correct 503 ms 5928 KB Output is correct
26 Correct 493 ms 5928 KB Output is correct
27 Correct 499 ms 5928 KB Output is correct
28 Correct 549 ms 5928 KB Output is correct
29 Correct 473 ms 5928 KB Output is correct
30 Correct 586 ms 5928 KB Output is correct