Cod sursa(job #2699224)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 23 ianuarie 2021 21:30:25
Problema Ciclu Eulerian Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.48 kb
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define readFast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fin cin
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define debug(v,n) for (int i = 1; i <= (n); ++i) cout << v[i] << " ";
#define next cout << '\n'
using namespace std;
//ifstream fin("date.in.txt");

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
int a[N], b[N], c[N], n, q, cnt;
ll dp[N][3];

void read(int * a) {
    string s;
    fin >> s;
    for (int i = 1; i <= n; ++i)
        a[i] = s[i-1] - '0';
}

int main() {
    fin >> n >> q;

    read(a);
    read(b);
    read(c);
    /*Tipuri
    1 -> 1 + 1 = 2 / ok                     || 0 >- 0
    2 -> 1 + 0 = 2 / necesita               || 0 >- 1
    3 -> 5 + 5 = 0 / genereaza              || 1 >- 0
    4 -> 5 + 5 = 1 / necesita si genereaza  || 1 >- 1
    5 -> 2 + 2 = 3 / bad
    */
    for (int t = 0; t <= q; ++t) {
        for (int i = 1; i <= n; ++i)
            dp[i][0] = dp[i][1] = 0;

        for (int i = 1; i <= n; ++i) {

            if(a[i] + b[i] == c[i]) {
                dp[i][0] = dp[i - 1][0] + 1;
              //  cout << "ok   ";
            }
            else if(a[i] + b[i] == c[i] - 1) {
                dp[i][1] = dp[i - 1][0] + 1;
               // cout << "necesita  ";
            }

            else if((a[i] + b[i]) % 10 == c[i]) {
                dp[i][0] = dp[i - 1][1] ;
               // cout << "genereaza  ";
            }
            else if(a[i] + b[i] + 1 == c[i] + 10) {
                dp[i][1] = dp[i - 1][1];
               // cout << "necesita si genereaza ";
            }
           // else
              //  cout << "BAD ";
            dp[i][1] = (dp[i][1] + dp[i - 1][1]) % MOD;
            dp[i][0] = (dp[i][0] + dp[i - 1][0]) % MOD;
            //cout << dp[i][1] << " " << dp[i][0] << '\n';
        }
        cout << (dp[n][0] + 1) % MOD << '\n';

        if(t < q) {
            int lin, col, x;
            fin >> lin >> col >> x;
            if(lin == 1)
                a[col] = x;
            if(lin == 2)
                b[col] = x;
            if(lin == 3)
                c[col] = x;
        }
    }
    return 0;
}
 /*stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
~Benq~
*/