CSES - Aalto Competitive Programming 2024 - wk12 - Wed - Results
Submission details
Task:Dice Summation
Sender:Rasse
Submission time:2024-11-27 16:26:19 +0200
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'void mP(std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&, long long int)':
input/code.cpp:51:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int i = 0; i < outMat.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
input/code.cpp:52:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for (int j = 0; j < outMat[i].size(); j++)
      |                             ~~^~~~~~~~~~~~~~~~~~
input/code.cpp:60:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [...

Code

#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <climits>
#include <cmath>
#include <functional>
#include <type_traits>
#include <fstream>
#include <bitset>
#include <complex>
#include <iomanip>
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp> // gcc only
template<typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
 
#define int long long
using namespace std;
 
int p(int base, int power, int mod)
{
    if (power == 0)
        return 1;
    if (power % 2 == 0)
    {
        int r = p(base, power/2, mod);
        return (r*r) % mod;
    }
    else
        return (p(base, power-1, mod)*base) % mod;
}
 
int LCM(int a, int b)
{
    return (a / __gcd(a, b)) * b;
}
 
int mod = 1e9+7;
 
void mP(vector<vector<int>>& inMat, vector<vector<int>>& temp, vector<vector<int>>& outMat, int power) {
    if (power == 1)
    {
        for (int i = 0; i < outMat.size(); i++)
            for (int j = 0; j < outMat[i].size(); j++)
                outMat[i][j] = inMat[i][j];
        return;
    }
    if (power % 2 == 0)
    {
        mP(inMat, temp, outMat, power / 2);
        swap(outMat, temp);
        for (int i = 0; i < outMat.size(); i++)
            for (int j = 0; j < outMat[i].size(); j++)
            {
                outMat[i][j] = 0;
                for (int idx = 0; idx < outMat.size(); idx++)
                {
                    outMat[i][j] += temp[i][idx] * temp[idx][j];
                    outMat[i][j] %= mod;
                }
            }
    }
    else
    {
        mP(inMat, temp, outMat, power-1);
        swap(outMat, temp);
        for (int i = 0; i < outMat.size(); i++)
            for (int j = 0; j < outMat[i].size(); j++)
            {
                outMat[i][j] = 0;
                for (int idx = 0; idx < outMat.size(); idx++)
                {
                    outMat[i][j] += temp[i][idx] * inMat[idx][j];
                    outMat[i][j] %= mod;
                }
            }
    }
}
 
void solve()
{
    int n;
    cin >> n;
 
    vector<int> init{1, 2, 4, 8, 16, 32};
 
    if (n == 1)
    {
        cout << init[n-1];
        return;
    }
 
    vector<vector<int>> mat(6, vector<int>(6, 0));
    for (int i = 1; i < mat.size(); i++)
        mat[i-1][i] = 1;
    for (int i = 0; i < mat.size(); i++)
        mat[mat.size()-1][i] = 1;
    
    
    vector<vector<int>> mat2(6, vector<int>(6, 0));
    vector<vector<int>> outMat(6, vector<int>(6, 0));
    
    mP(mat, mat2, outMat, n-1);
 
    for (int x = 0; x < 1; x++)
    {
        int res = 0;
        for (int i = 0; i < init.size(); i++)
        {
            res += outMat[x][i] * init[i];
            res %= mod;
        }
        cout << res << ' ';
    }
 
 
} 
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int t = 1;
 
    //cin >> t;
 
    for (int i = 0; i < t; i++)
    {
        solve();
        //cout.flush();
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output
1

user output
1

Test 2

Verdict: ACCEPTED

input
2

correct output
2

user output

Test 3

Verdict: ACCEPTED

input
3

correct output
4

user output

Test 4

Verdict: ACCEPTED

input
4

correct output
8

user output

Test 5

Verdict: ACCEPTED

input
5

correct output
16

user output
16 

Test 6

Verdict: ACCEPTED

input
6

correct output
32

user output
32 

Test 7

Verdict: ACCEPTED

input
7

correct output
63

user output
63 

Test 8

Verdict: ACCEPTED

input
8

correct output
125

user output
125 

Test 9

Verdict: ACCEPTED

input
9

correct output
248

user output
248 

Test 10

Verdict: ACCEPTED

input
10

correct output
492

user output
492 

Test 11

Verdict: ACCEPTED

input
50

correct output
660641036

user output
660641036 

Test 12

Verdict: ACCEPTED

input
1000

correct output
937196411

user output
937196411 

Test 13

Verdict: ACCEPTED

input
123456

correct output
113810539

user output
113810539 

Test 14

Verdict: ACCEPTED

input
654321

correct output
615247550

user output
615247550 

Test 15

Verdict: ACCEPTED

input
999998

correct output
39372206

user output
39372206 

Test 16

Verdict: ACCEPTED

input
999999

correct output
511319454

user output
511319454 

Test 17

Verdict: ACCEPTED

input
1000000

correct output
874273980

user output
874273980 

Test 18

Verdict: ACCEPTED

input
1001

correct output
94201505

user output
94201505 

Test 19

Verdict: ACCEPTED

input
999997

correct output
74225807

user output
74225807 

Test 20

Verdict: ACCEPTED

input
40

correct output
567401756

user output
567401756