QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#197862#6960. Make 2PPP#AC ✓16ms3576kbC++172.1kb2023-10-02 21:00:152023-10-02 21:00:16

Judging History

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

  • [2023-10-02 21:00:16]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:3576kb
  • [2023-10-02 21:00:15]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define X first
#define Y second

const ll mod = 1000000007;

vector<vector<vector<ll>>> W0;


vector<ll> C;

const ll K = 6;

void upd(ll d, ll q)
{
    vector<vector<ll>> W = W0[q];
    while (d>0)
    {
        if (d&1)
        {
            vector<ll> C2(K);
            for (ll i=0;i<K;i++)
            {
                for (ll j=0;j<K;j++) C2[j] = (C2[j]+C[i]*W[i][j])%mod;
            }
            C = C2;
        }
        d >>= 1LL;
        vector<vector<ll>> W2(K,vector<ll>(K));
        for (ll i=0;i<K;i++)
        {
            for (ll j=0;j<K;j++)
            {
                for (ll k=0;k<K;k++)
                {
                    W2[i][k] = (W2[i][k]+W[i][j]*W[j][k])%mod;
                }
            }
        }
        W = W2;
    }
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll,ll>> Q;
    for (ll i=0;i<m;i++)
    {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        Q.push_back({x,y});
    }
    W0.clear();
    W0.resize(4,vector<vector<ll>>(K,vector<ll>(K)));
    W0[0][0][1] = 1;
    W0[0][2][2] = 1;
    W0[0][3][0] = 1;
    W0[1][0][0] = 1;
    W0[1][1][2] = 1;
    W0[1][2][3] = 1;
    W0[2][1][3] = 1;
    W0[0][1][4] = 1;
    W0[1][4][5] = 1;
    W0[0][5][3] = 1;
    for (ll j=0;j<3;j++)
    {
        for (ll x=0;x<K;x++)
        {
            for (ll y=0;y<K;y++) W0[3][x][y] += W0[j][x][y];
        }
    }
    C.clear();
    C.resize(K);
    C[0] = 1;
    ll prv = -1;
    for (ll i=0;i<Q.size();i++)
    {
        upd(Q[i].X-prv-1,3);
        prv = Q[i].X;
        if (Q[i].Y>2)
        {
            cout << 0 << "\n";
            return;
        }
        upd(1,Q[i].Y);
    }
    upd(n-prv-1,3);
    cout << C[0] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
//    freopen("input.txt", "r", stdin);
//#endif
    ll T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 3576kb

input:

10
461852149215451876 100
2606377861630340 1
4900099439792445 2
8529469964880646 1
10971270259972783 2
15192703197468854 2
21935781810578068 3
29971403782119190 1
34501042417520226 3
40359003874545562 3
46480157006014501 2
52478331952908009 1
55428584949575246 3
62368645204551626 3
69112449621347466...

output:

577575014
614065891
304260321
891916472
0
382938711
27287182
0
11286050
939192368

result:

ok 10 lines