# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958652 | Mher777 | Trading (IZhO13_trading) | C++17 | 1 ms | 2392 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 100005;
int n, m, a[4][N], dp[N][(1 << 2) + 4], msk[N];
int main()
{
cin >> n >> m;
while (m--)
{
int y, x;
scanf("%d%d", &x, &y);
y--;
msk[x] |= (1 << y);
}
dp[0][3] = 1;
for (int i = 0; i <= n; i++)
{
for (int mask = 0; mask < (1 << 2); mask++)
{
if ((mask & msk[i]) != msk[i])
continue;
//cout << "dp[" << i << "][" << mask << "]=" << dp[i][mask] << endl;
for (int nxt = 0; nxt < (1 << 2); nxt++)
{
if ((nxt & msk[i + 1]) != msk[i + 1])
continue;
LL x = 1;
for (int j = 0; j <= 1; j++)
{
int bit1 = (bool)(mask & (1 << j));
int bit2 = (bool)(nxt & (1 << j));
if (bit1 == 0 && (bit2 == 0 || ((1 << j) & msk[i + 1]) != 0))
x = 0;
}
dp[i + 1][nxt] += (x * dp[i][mask]) % mod;
dp[i + 1][nxt] %= mod;
}
}
if (msk[i + 1] == 0)
{
dp[i + 1][3] += dp[i][3];
dp[i + 1][3] %= mod;
}
}
cout << dp[n][3] << endl;
return 0;
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |