QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390429#7838. 往日之影Froranzen0 1ms5752kbC++233.5kb2024-04-15 15:30:232024-04-15 15:30:23

Judging History

This is the latest submission verdict.

  • [2024-04-15 15:30:23]
  • Judged
  • Verdict: 0
  • Time: 1ms
  • Memory: 5752kb
  • [2024-04-15 15:30:23]
  • Submitted

answer

#include <bits/stdc++.h>
#define rep(i, f, t) for(int i(f); i <= t; ++i)
#define re(i, t) for(int i(1); i <= t; ++i)
#define per(i, t, f) for(int i(t); i >= f; --i)
#define pe(i, t) for(int i(t); i >= 1; --i) 
#define nx(i, u) for(int i(head[u]); i; i = e[i].nxt)
typedef long long ll;
typedef unsigned long long ull; 
using namespace std;
typedef pair <int, int> pii;
#define pb push_back
#define eb emplace_back 
#define fi first
#define se second
#define ix(l, r) ((l + r) | (l != r))  
#define mp(i, j) (make_pair(i, j))
//#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, buf1[1 << 21];
inline char gc() {return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;}
template<class I>
inline void read(I &x) {x = 0;I f = 1;char c = gc();while (c < '0' || c > '9') {if (c == '-') {f = -1;} c = gc();}while (c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc();}x *= f;}
template<class I>
inline void write(I x) {if (x == 0) {putchar('0');return;}I tmp = x > 0 ? x : -x;if (x < 0) {putchar('-');}int cnt = 0;while (tmp > 0) {buf1[cnt++] = tmp % 10 + '0';tmp /= 10;}while (cnt > 0)putchar(buf1[--cnt]);}
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')
} using namespace IO;
#define look_memory cerr<<abs(&sT-&eD)/1024.0/1024<<'\n'
int sT;

int T, mod;
int val[5], n;

void MOD (int &x) {
	x = x >= mod ? x - mod : x;
}

struct cp {

	int a, b;
	cp operator + (const cp &rhs) {cp c; MOD(c.a = a + rhs.a), MOD(c.b = b + rhs.b); return c;}
	cp operator - (const cp &rhs) {cp c; MOD(c.a = a + mod - rhs.a), MOD(c.b = b + mod - rhs.b); return c;}
	cp operator * (const cp &rhs) {cp c; MOD(c.a = 1ll * a * rhs.a % mod + mod - 1ll * b * rhs.b % mod), MOD(c.b = 1ll * a * rhs.b % mod + 1ll * b * rhs.a % mod); return c;}
	cp operator * (const int &v)  {cp c; c.a = 1ll * a * v % mod, c.b = 1ll * b * v % mod; return c;}
	cp(int x=0,int y=0) {a=x,b=y;}

}w[5];

cp ksm (cp a, int b) {
	if(!b) return cp(1,0);
	cp ans=a, base=a;
	--b;
	while(b) {
		if(b&1) ans = ans * base;
		base = base * base;
		b >>= 1;
	}
	return ans;
}

int ksm (int a, int b) {
	ll ans = 1, base = a;
	while(b) {
		if(b & 1) ans = ans * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return ans;
}

void solve () {
	cp ans;
	int inv2 = (mod+1)/2;
	cp x[2], y[2];
	x[0] = cp(inv2, inv2), x[1] = cp(inv2, mod-inv2);
	y[0] = ksm(x[0], n-2), y[1] = ksm(x[1], n-2);
	rep(i, 0, 4) {
		int tmp = 1;
		if(i < 4) tmp = val[i];
		--val[i];
		rep(j, 0, 4) {
			int lst = tmp;
			if(j < 4) tmp = 1ll * tmp * val[j] % mod;
			--val[j];
			int op = 0;
			rep(k, 0, 3) if(val[k] < 0) op = 1;
			if(!op){
			rep(k, 0, 1) {
				cp res;
				int sz = 0;
				rep(l, 0, 3) {
					sz += val[l] * l;
				}
				res.a = ((k&1) && (sz&1)) ? (mod - 1) : 1;
				if(i < 4 && i) res = res * w[3-i+1];
				if(j < 4 && j) res = res * w[j];
				if(i < 4) { 
					if(j < 4) res = res * y[0] * y[1];
					else res = res * y[k] * x[k];
				}
				else if(j < 4) res = res * y[k^1] * x[k^1];
				ans = ans + res * tmp;
			}}
			++val[j];
			tmp = lst;
		}
		++val[i];
	} 
	int lc = 1ll * ans.a * ksm(ksm(4, n), mod-2) % mod;
	outn(lc);
}

int main () {
	read(T), read(mod);
	w[0] = cp(1,0), w[1] = cp(0,1), w[2] = cp(mod-1,0), w[3] = cp(0,mod-1);
	while(T--) {
		read(n);
		rep(i, 0, 3) read(val[i]);
		solve();			 
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 1ms
memory: 5708kb

input:

1 998244353
3
1 1 0 1

output:

0

result:

ok single line: '0'

Test #2:

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

input:

1 998244353
7
0 2 1 4

output:

998069185

result:

ok single line: '998069185'

Test #3:

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

input:

1 998244353
4
0 1 0 3

output:

0

result:

ok single line: '0'

Test #4:

score: -10
Wrong Answer
time: 1ms
memory: 5580kb

input:

1 998244353
2
1 0 1 0

output:

124780544

result:

wrong answer 1st lines differ - expected: '0', found: '124780544'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 0ms
memory: 5708kb

input:

999 999999001
2
2 0 0 0
3
3 0 0 0
4
4 0 0 0
5
5 0 0 0
6
6 0 0 0
7
7 0 0 0
8
8 0 0 0
9
9 0 0 0
10
10 0 0 0
11
11 0 0 0
12
12 0 0 0
13
13 0 0 0
14
14 0 0 0
15
15 0 0 0
16
16 0 0 0
17
17 0 0 0
18
18 0 0 0
19
19 0 0 0
20
20 0 0 0
21
21 0 0 0
22
22 0 0 0
23
23 0 0 0
24
24 0 0 0
25
25 0 0 0
26
26 0 0 0
27...

output:

374999626
874999126
359374641
919920956
691222454
586081873
33512082
496961574
790501684
206445579
708073277
492142887
486007979
21786019
802052117
198521403
854660059
658779344
904643630
538486221
357736277
949763680
94144464
342842045
695164947
276856011
552666277
813428208
572457238
910726512
177...

result:

wrong answer 1st lines differ - expected: '499999501', found: '374999626'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%