QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113861#5547. Short FunctionPetroTarnavskyi#WA 1ms3440kbC++171.7kb2023-06-19 19:27:462023-06-19 19:27:48

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 19:27:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3440kb
  • [2023-06-19 19:27:46]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int mod = 998244353;
int add(int a, int b){
	return (a + b > mod) ? (a + b - mod) : (a + b);
}
int sub(int a, int b){
	return (a - b < 0) ? (a - b + mod) : (a - b);
}
int mult(int a, int b){
	return 1LL* a * b % mod;
}
int binpow(int a, int n){
	int res = 1;
	while(n){
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

int inv(int x)
{
	return binpow(x, mod - 2);
}
int bw(int k, int n){
	int res = 1;
	int a = 2;
	while(k){
		if(k & 1)
			res = 1ll * res * a % n;
		a = 1ll * a * a % n;
		k /= 2;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	VI a(n);
	FOR (i, 0, n) cin >> a[i];
	VI pr(n + 1, 1);
	VI ipr(n + 1, 1);
	FOR (i, 0, n) 
	{
		pr[i + 1] = mult(pr[i], a[i]);
		ipr[i + 1] = inv(pr[i + 1]);
	}
	int all = pr[n];
	int pos = bw(k, n);
	
	int cnt = mult(sub(binpow(2, k), pos), inv(n));
	
	int pachka = binpow(all, cnt);
	if(pos == 0){
		FOR(i, 0, n)
			cout << pachka << " ";
		cout << endl;
		return 0;
	}
	FOR (i, 0, n)
	{
		//[i, pos)
		int res = pachka;
		if(pos < i){
			int cur = pr[pos];
			cur = mult(cur, mult(all, ipr[i]));
			res = mult(res, cur);
		}else{
			res = mult(res, mult(pr[pos], ipr[i]));
		}
		cout << res << " ";
		pos = (pos + 1) % n;
	}
	cout << endl;
	
	return 0;
}


详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

input:

5 2
1 2 3 4 5

output:

24 120 60 40 30 

result:

ok 5 number(s): "24 120 60 40 30"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

8 3
12 5 16 14 10 6 9 2

output:

14515200 14515200 14515200 14515200 14515200 14515200 14515200 14515200 

result:

ok 8 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3432kb

input:

6 10
3 7 8 2 9 5

output:

56347321 169041963 833775940 811788154 844769833 639990479 

result:

ok 6 numbers

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3440kb

input:

2 100
1 2

output:

152295411 152295411 

result:

wrong answer 1st numbers differ - expected: '917380677', found: '152295411'