Submission #313277

# Submission time Handle Problem Language Result Execution time Memory
313277 2020-10-15T16:03:56 Z CaroLinda Semafor (COI20_semafor) C++14
100 / 100
340 ms 4736 KB
#include <bits/stdc++.h>

#define debug printf
#define lp(i,a,b) for(int i = a; i < b; i++ )
#define pii pair<int,int>
#define sz(x) (int)(x.size())
#define ll long long 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

const ll MOD = 1e9+7 ;

using namespace std ;

struct Matrix
{

	vector< vector<ll> > vec ;

	Matrix(int n = 0)
	{
		vec.resize(n, vector<ll>(n,0) ) ;
	}

	Matrix operator * (Matrix other) const
	{
		int n = sz(vec) ;

		Matrix newMatrix(n) ;

		for(int i = 0 ; i < n ; i++ )
			for(int j = 0 ; j < n ; j++ )
				for(int g = 0 ; g < n ; g++ )
				{
					ll toSum = vec[i][g] * other.vec[g][j] ;
					toSum %= MOD ;

					newMatrix.vec[i][j] += toSum ;
					if(newMatrix.vec[i][j] >= MOD ) newMatrix.vec[i][j] -= MOD ;

				}

		return newMatrix ;
	}

} ;

int m, x ;
ll n , k ;
int myMask[10] = {10,2, 1+8, 1+2+4, 16+2, 1+16+4, 8+4, 1+2, 31-2, 31-8 } ;
int matDiff[120][120] ;

bool isOn(int i, int m) { return ((1<<i)&m) != 0 ; }

Matrix expo(Matrix x, ll num )
{
	if(num == 1) return x ;

	Matrix aux = expo(x, num>>1LL ) ;
	aux = aux*aux ;

	if(num&1) aux = aux*x ;

	return aux ;
}

int main()
{

	scanf("%d%lld%lld%d", &m, &n, &k , &x ) ;

	int lim = (m == 1) ? 6 : 11 ;
	Matrix findK(lim) ;
	Matrix findR(lim) ;
		
	for(int diff = 0 ; diff < lim ; diff++ )
	{
		if(diff)
			findK.vec[diff-1][diff] = diff ;

		if(diff+1 < lim)
			findK.vec[diff+1][diff] = lim-1-diff ;

	}


	Matrix base(lim) ;
	base.vec[0][0] = 1 ;

	if( (n%k) > 0 ) findR = base * expo( findK, n%k ) ;
	findK = base*expo(findK, k);

	lim = (m == 1) ? 10 : 100 ;

	Matrix findDp(lim) ;

	for(int i = 0 ; i < lim ; i++)
		for(int j = 0 ; j < lim ; j++ )
		{
			int bitmask1 = (myMask[i/10] << 5) + myMask[i%10] ;
			int bitmask2 = (myMask[j/10] << 5) + myMask[j%10] ;
			int diff = 0 ;

			for(int g = 0 ; g < 10 ; g++ )
				diff += (isOn(g,bitmask1) != isOn(g, bitmask2)) ;

			findDp.vec[i][j] = findK.vec[0][diff] ;
			matDiff[i][j] = diff ;

		}

	vector<ll> dp(lim+1,0LL) ;

	findDp = expo( findDp, n/k ) ;

	for(int i = 0 ; i < lim ; i++ ) 
	{
		if( n%k == 0 )
		{
			dp[i] = findDp.vec[x][i] ;
			continue ;
		}

		for(int g = 0 ; g < lim ; g++ )
		{
			ll toSum = findDp.vec[x][g] * findR.vec[0][ matDiff[i][g] ] ;
			dp[i] += toSum % MOD ;

			if( dp[i] >= MOD ) dp[i] -= MOD;
		}
	}

	for(int i = 0 ; i<lim ; i++ ) printf("%lld\n" , dp[i] ) ;

}

Compilation message

semafor.cpp: In function 'int main()':
semafor.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |  scanf("%d%lld%lld%d", &m, &n, &k , &x ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1408 KB Output is correct
2 Correct 163 ms 2692 KB Output is correct
3 Correct 252 ms 3840 KB Output is correct
4 Correct 340 ms 4352 KB Output is correct
5 Correct 320 ms 4352 KB Output is correct
6 Correct 293 ms 4352 KB Output is correct
7 Correct 323 ms 4480 KB Output is correct
8 Correct 305 ms 4736 KB Output is correct
9 Correct 313 ms 4736 KB Output is correct
10 Correct 301 ms 4352 KB Output is correct
11 Correct 28 ms 896 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 314 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1408 KB Output is correct
2 Correct 163 ms 2692 KB Output is correct
3 Correct 252 ms 3840 KB Output is correct
4 Correct 340 ms 4352 KB Output is correct
5 Correct 320 ms 4352 KB Output is correct
6 Correct 293 ms 4352 KB Output is correct
7 Correct 323 ms 4480 KB Output is correct
8 Correct 305 ms 4736 KB Output is correct
9 Correct 313 ms 4736 KB Output is correct
10 Correct 301 ms 4352 KB Output is correct
11 Correct 28 ms 896 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 314 ms 4480 KB Output is correct
14 Correct 24 ms 896 KB Output is correct
15 Correct 117 ms 2048 KB Output is correct
16 Correct 185 ms 3072 KB Output is correct
17 Correct 251 ms 3712 KB Output is correct
18 Correct 268 ms 3968 KB Output is correct
19 Correct 228 ms 3968 KB Output is correct
20 Correct 269 ms 3968 KB Output is correct
21 Correct 307 ms 4736 KB Output is correct
22 Correct 306 ms 4480 KB Output is correct
23 Correct 249 ms 3840 KB Output is correct
24 Correct 268 ms 3840 KB Output is correct
25 Correct 256 ms 4096 KB Output is correct
26 Correct 10 ms 896 KB Output is correct
27 Correct 20 ms 896 KB Output is correct
28 Correct 187 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 54 ms 1408 KB Output is correct
11 Correct 163 ms 2692 KB Output is correct
12 Correct 252 ms 3840 KB Output is correct
13 Correct 340 ms 4352 KB Output is correct
14 Correct 320 ms 4352 KB Output is correct
15 Correct 293 ms 4352 KB Output is correct
16 Correct 323 ms 4480 KB Output is correct
17 Correct 305 ms 4736 KB Output is correct
18 Correct 313 ms 4736 KB Output is correct
19 Correct 301 ms 4352 KB Output is correct
20 Correct 28 ms 896 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 314 ms 4480 KB Output is correct
23 Correct 24 ms 896 KB Output is correct
24 Correct 117 ms 2048 KB Output is correct
25 Correct 185 ms 3072 KB Output is correct
26 Correct 251 ms 3712 KB Output is correct
27 Correct 268 ms 3968 KB Output is correct
28 Correct 228 ms 3968 KB Output is correct
29 Correct 269 ms 3968 KB Output is correct
30 Correct 307 ms 4736 KB Output is correct
31 Correct 306 ms 4480 KB Output is correct
32 Correct 249 ms 3840 KB Output is correct
33 Correct 268 ms 3840 KB Output is correct
34 Correct 256 ms 4096 KB Output is correct
35 Correct 10 ms 896 KB Output is correct
36 Correct 20 ms 896 KB Output is correct
37 Correct 187 ms 3200 KB Output is correct
38 Correct 5 ms 768 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 307 ms 4736 KB Output is correct
46 Correct 298 ms 4608 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 1 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 90 ms 1800 KB Output is correct