QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345139#1061. 染色hos.lyric🐇100 ✓23ms8584kbC++148.5kb2024-03-06 10:50:542024-03-06 10:50:54

Judging History

This is the latest submission verdict.

  • [2024-03-06 10:50:54]
  • Judged
  • Verdict: 100
  • Time: 23ms
  • Memory: 8584kb
  • [2024-03-06 10:50:54]
  • Submitted

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 1'000'000'009;
using Mint = ModInt<MO>;


constexpr int MAX_N = 100'010;


namespace ds_brute {
int len;
Mint sum, fs[MAX_N];
void print() {
  cerr << "[ds] sum = " << sum << ", fs = "; pv(fs + 1, fs + (len + 1));
}
void init(int len_) {
  len = len_;
  sum = 0;
  fill(fs, fs + (len + 1), 0);
}
void change(int a, Mint val) {
  assert(1 <= a); assert(a <= len);
  sum -= fs[a];
  sum += fs[a] = val;
}
Mint get(int a) {
  assert(1 <= a); assert(a <= len);
  return fs[a];
}
void mul(Mint val) {
  sum *= val;
  for (int a = 1; a <= len; ++a) fs[a] *= val;
}
void add(Mint val) {
  sum += len * val;
  for (int a = 1; a <= len; ++a) fs[a] += val;
}
}  // ds_brute


namespace ds {
int len;
Mint sum, fs[MAX_N];
// f -> p f + q
Mint p, q;
int zeit, zero, when[MAX_N];
void init(int len_) {
  len = len_;
  sum = 0;
  fill(fs, fs + (len + 1), 0);
  p = 1;
  q = 0;
  zeit = 0;
  zero = 0;
  fill(when, when + (len + 1), 0);
}
Mint get(int a) {
  assert(1 <= a); assert(a <= len);
  return (zero < when[a]) ? (p * fs[a] + q) : q;
}
void change(int a, Mint val) {
  assert(1 <= a); assert(a <= len);
  sum -= get(a);
  sum += val;
  fs[a] = (val - q) / p;
  when[a] = ++zeit;
}
void mul(Mint val) {
  sum *= val;
  if (val) {
    p *= val;
    q *= val;
  } else {
    p = 1;
    q = 0;
    zero = ++zeit;
  }
}
void add(Mint val) {
  sum += len * val;
  q += val;
}
}  // ds


int N, C;
int A[2][MAX_N];

enum { AB, BA, Ax, xA, Bx, xB, xy, U };
Mint dp[MAX_N][U], all[MAX_N];

int main() {
  for (; ~scanf("%d%d", &N, &C); ) {
    for (int x = 0; x < 2; ++x) for (int y = 0; y < N; ++y) {
      scanf("%d", &A[x][y]);
    }
    
    /*
      [from][to]
      to: for particular x, y (not the sum)
    */
    const Mint trans[U][U] = {
      //        AB   BA   Ax   xA   Bx   xB   xy
      /* AB */ {0  , 1  , 0  , 1  , 1  , 0  , 1  },
      /* BA */ {1  , 0  , 1  , 0  , 0  , 1  , 1  },
      /* A? */ {0  , C-2, 0  , C-2, C-3, C-2, C-3},
      /* ?A */ {C-2, 0  , C-2, 0  , C-2, C-3, C-3},
      /* B? */ {C-2, 0  , C-3, C-2, 0  , C-2, C-3},
      /* ?B */ {0  , C-2, C-2, C-3, C-2, 0  , C-3},
      /* ?? */ {Mint(C-2)*(C-3), Mint(C-2)*(C-3), Mint(C-3)*(C-3), Mint(C-3)*(C-3), Mint(C-3)*(C-3), Mint(C-3)*(C-3), Mint(C-2)*(C-3)-2*(C-3)+1},
    };
    memset(dp, 0, sizeof(dp));
    dp[0][AB] = 1;
    for (int n = 0; n < N; ++n) {
      for (int u = 0; u < U; ++u) for (int v = 0; v < U; ++v) {
        dp[n + 1][v] += dp[n][u] * trans[u][v];
      }
    }
    for (int n = 0; n <= N; ++n) {
      all[n] = 0;
      all[n] += (dp[n][AB] + dp[n][BA]);
      all[n] += (C-2) * (dp[n][Ax] + dp[n][xA] + dp[n][Bx] + dp[n][xB]);
      all[n] += Mint(C-2)*(C-3) * dp[n][xy];
    }
// cerr<<"all = ";pv(all,all+(N+1));
    
    bool ok = true;
    for (int x = 0; x < 2; ++x) for (int y = 0; y < N - 1; ++y) if (A[x][y] && A[x][y + 1]) ok = ok && (A[x][y] != A[x][y + 1]);
    for (int y = 0; y < N; ++y) if (A[0][y] && A[1][y]) ok = ok && (A[0][y] != A[1][y]);
    Mint ans = 0;
    if (ok) {
      vector<int> ys;
      for (int y = 0; y < N; ++y) if (A[0][y] || A[1][y]) {
        ys.push_back(y);
      }
      const int ysLen = ys.size();
      if (ysLen == 0) {
        ans = Mint(C)*(C-1) * all[N - 1];
      } else {
        ds::init(C);
        {
          const int y = ys[0];
          const int x = A[0][y] ? 0 : 1;
          const int a = A[x][y];
          ds::add(all[y - 0]);
          ds::change(a, 0);
          if (A[0][y] && A[1][y]) {
            ds::mul(0);
            ds::change(A[1][y], all[y - 0]);
          }
// ds::print();
        }
        for (int i = 0; i < ysLen - 1; ++i) {
          const int y0 = ys[i];
          const int y1 = ys[i + 1];
          const Mint *d = dp[y1 - y0];
// cerr<<y0<<" -> "<<y1<<": d = ";pv(d,d+U);
          const int x0 = A[0][y0] ? 0 : 1;
          const int x1 = A[0][y1] ? 0 : 1;
          const bool s = (x0 != x1);
          const int a0 = A[x0][y0];
          const int a1 = A[x1][y1];
          if (a0 != a1) {
            const Mint sum = ds::sum;
            const Mint f1 = ds::get(a1);
            ds::mul(d[s?Bx:xB] - d[xy]);
            ds::add(f1 * d[s?xB:Bx] + (sum - f1) * d[xy]);
            ds::change(a0, f1 * d[s?AB:BA] + (sum - f1) * d[s?Ax:xA]);
          } else {
            const Mint sum = ds::sum;
            ds::mul(d[s?BA:AB] - d[s?xA:Ax]);
            ds::add(sum * d[s?xA:Ax]);
          }
          ds::change(a1, 0);
          if (A[0][y1] && A[1][y1]) {
            const Mint f = ds::get(A[1][y1]);
            ds::mul(0);
            ds::change(A[1][y1], f);
          }
// ds::print();
        }
        {
          const int y = ys[ysLen - 1];
          ans += ds::sum * all[(N-1) - y];
        }
      }
    }
    printf("%u\n", ans.x);
  }
  return 0;
}

詳細信息

Subtask #1:

score: 44
Accepted

Test #1:

score: 44
Accepted
time: 3ms
memory: 7040kb

input:

10000 9973
2926 0 0 0 2176 0 0 0 0 0 0 0 0 0 0 0 0 5892 0 0 107 0 0 0 0 0 0 0 6953 0 0 0 0 0 2120 4802 0 0 0 0 0 0 0 0 0 0 0 6476 0 0 847 0 0 0 0 0 0 0 0 0 3336 0 0 0 0 0 0 0 0 0 0 0 0 5279 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8435 0 0 0 0 0 0 0 0 0 2960 0 1565 0 0 0 742 0 1897 0 0 0 0 0 0 0 0 0 665 0 0 0 62...

output:

517694800

result:

ok single line: '517694800'

Test #2:

score: 0
Accepted
time: 3ms
memory: 6692kb

input:

10000 9967
3971 4199 4265 2901 0 0 7989 0 0 0 0 0 0 0 0 6112 0 0 0 0 0 0 0 0 2780 0 0 0 0 0 0 0 0 1818 0 0 0 0 0 0 0 0 0 0 4248 9857 0 0 0 0 4221 0 0 0 0 0 0 0 0 583 0 0 0 8748 4101 0 0 4735 0 0 0 0 0 1439 2549 0 0 0 0 0 0 0 7561 0 0 7522 0 0 0 0 8292 0 0 0 0 0 1149 0 0 0 5840 0 0 0 0 0 0 0 0 0 0 59...

output:

660134576

result:

ok single line: '660134576'

Test #3:

score: 0
Accepted
time: 0ms
memory: 6708kb

input:

10000 9949
2583 0 0 0 0 0 0 290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6489 0 0 0 7942 0 752 0 4993 0 0 0 0 0 0 0 0 0 0 0 0 4801 0 3582 0 0 0 0 9263 0 0 0 1086 0 0 0 0 0 0 0 0 0 0 0 0 0 8738 0 0 0 0 0 0 0 0 0 0 0 0 729 0 0 0 8085 0 7422 0 0 0 0 9462 0 0 0 0 0 0 0 6328 37 0 0 0 0 0 0 0 9...

output:

379398650

result:

ok single line: '379398650'

Test #4:

score: 0
Accepted
time: 3ms
memory: 6732kb

input:

10000 9941
1321 0 0 0 0 0 2682 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6517 0 0 0 0 0 5016 0 0 0 0 8111 0 0 0 0 6278 0 0 0 0 0 0 0 0 0 0 0 0 6113 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7472 0 9178 0 0 0 0 0 0 0 0 1742 0 7710 0 0 0 0 0 0 6760 200 0 0 0 0 8773 0 0 0 0 0 0 0 0 0 0 0 1300 0 0 0 0 0 2903 0 ...

output:

336132186

result:

ok single line: '336132186'

Test #5:

score: 0
Accepted
time: 0ms
memory: 7032kb

input:

10000 9931
2153 0 0 0 0 0 4461 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4225 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6072 0 0 0 0 0 8259 0 0 0 0 0 0 0 0 0 0 0 0 9341 0 0 0 9417 0 7681 3178 9725 0 0 0 0 0 0 0 0 0 5016 0 0 9282 0 0 0 8054 0 0 0 0 2156 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1943 0 0 5978 2492 0 0 0 97...

output:

779579773

result:

ok single line: '779579773'

Test #6:

score: 0
Accepted
time: 0ms
memory: 7036kb

input:

10000 9929
5447 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5069 0 9494 0 0 0 0 9413 0 0 7771 0 0 0 0 0 0 0 0 189 9434 0 0 0 0 0 0 0 0 0 0 0 2606 0 0 0 0 0 0 0 0 0 0 0 0 3575 0 803 7312 8185 0 0 0 0 0 0 7496 0 0 0 0 0 0 0 0 0 6976 1013 0 0 0 0 3623 7520 0 0 0 4603 0 6479 0 0 0 0 0 0 0 0 0 0 0 0 9152 0...

output:

463819841

result:

ok single line: '463819841'

Test #7:

score: 0
Accepted
time: 3ms
memory: 6816kb

input:

10000 9923
904 1819 0 0 0 0 0 0 0 0 0 0 0 0 3348 0 0 0 0 8856 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3855 0 0 0 0 0 0 0 5462 2713 0 0 0 0 0 0 0 0 5869 0 0 0 0 0 3992 0 0 0 0 0 0 0 0 0 0 3664 0 0 0 0 0 4234 0 0 0 0 0 0 1005 0 0 0 6784 0 2397 0 0 0 3119 0 0 0 5067 0 9095 4324 5097 0 0 0 0 0 0 0 0 0 0 0 1...

output:

37692735

result:

ok single line: '37692735'

Test #8:

score: 0
Accepted
time: 4ms
memory: 6752kb

input:

10000 9907
862 0 0 0 0 0 0 0 0 0 0 2363 4649 0 0 0 0 0 139 0 0 0 0 0 0 0 0 0 0 0 0 7768 8937 0 0 0 0 4055 0 0 0 0 1274 0 0 0 0 0 0 0 0 0 0 0 0 0 8418 0 0 0 0 0 0 0 0 0 0 0 0 9264 0 0 0 0 0 0 3391 0 925 0 0 0 0 0 0 0 0 0 0 0 0 0 9184 0 0 0 2485 0 2516 0 1621 0 0 0 704 0 0 0 0 0 0 0 2976 0 0 0 0 0 0 0...

output:

351922656

result:

ok single line: '351922656'

Test #9:

score: 0
Accepted
time: 0ms
memory: 6736kb

input:

10000 9901
9545 0 0 0 0 0 1147 9738 0 0 0 0 0 0 151 0 0 7629 0 0 0 0 1497 0 0 0 0 0 0 0 0 0 0 4547 0 0 0 0 0 8062 0 0 0 0 0 0 0 0 0 0 7209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9296 0 0 7832 0 0 0 7929 4254 0 0 0 0 9378 0 0 0 4234 0 0 0 0 0 0 0 0 0 0 2673 0 0 0 4862 0 0 0 0 0 0 0 0 0 799...

output:

683001523

result:

ok single line: '683001523'

Test #10:

score: 0
Accepted
time: 0ms
memory: 6708kb

input:

10000 9887
3001 0 0 0 0 122 0 0 0 0 0 0 0 0 0 0 0 0 0 9843 0 0 0 1723 0 6717 0 0 0 0 0 0 0 0 0 1493 0 0 0 0 0 0 0 0 2208 0 0 4879 0 0 0 7191 82 0 0 0 0 0 0 0 0 0 6192 0 0 0 0 9867 0 0 0 0 0 0 5657 0 0 0 0 0 0 0 0 0 1229 4256 0 0 188 0 0 0 0 0 0 0 6766 7290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6193 0 0 0 83...

output:

906121765

result:

ok single line: '906121765'

Test #11:

score: 0
Accepted
time: 3ms
memory: 6992kb

input:

10000 9883
8140 0 0 0 0 0 0 0 0 0 0 1329 0 0 0 4768 0 4925 108 0 0 0 0 0 0 0 0 9604 0 5870 4255 0 0 0 0 0 0 0 0 0 0 0 1807 0 0 0 0 5089 0 0 0 248 1892 0 0 0 0 0 0 3940 0 0 0 0 617 0 5924 0 0 0 0 0 0 0 0 6136 0 0 0 0 0 0 2211 4740 0 0 0 0 0 0 0 0 0 1770 0 0 0 0 0 0 5321 0 0 0 1131 0 0 2026 0 8214 173...

output:

861710884

result:

ok single line: '861710884'

Subtask #2:

score: 32
Accepted

Dependency #1:

100%
Accepted

Test #12:

score: 32
Accepted
time: 4ms
memory: 7008kb

input:

10000 9973
1553 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4736 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5331 2364 0 0 0 9824 0 0 0 6056 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6868 0 0 7045 0 0 0 0 0 0 0 0 0 0 0 0 0 1531 0 0 4240 0 0 0 5287 0 0 0 0 0 0 7852 0 0 0 945...

output:

962033160

result:

ok single line: '962033160'

Test #13:

score: 0
Accepted
time: 3ms
memory: 6592kb

input:

10000 9967
0 0 0 0 0 0 0 0 0 0 0 9703 6206 0 171 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9330 2459 0 0 0 2135 3538 0 0 0 0 0 0 0 0 7649 0 0 1867 0 0 0 0 0 0 0 0 0 0 0 0 1116 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6494 2360 0 8811 0 1883 0 0 0 0 0 0 8462 0 0 0 0 0 0 3651 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2167 0 0 0 7371 ...

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 4ms
memory: 7008kb

input:

10000 9949
9132 0 0 0 0 0 0 0 0 817 0 0 0 0 0 0 9919 0 0 0 0 0 9585 6939 0 0 0 0 0 0 0 0 1298 0 7603 0 0 0 0 0 0 0 9070 2311 0 0 0 0 0 0 0 0 0 0 2235 0 8165 0 0 0 0 0 9930 0 0 0 0 0 8638 0 0 0 0 0 0 0 0 0 0 0 2260 6115 0 0 0 1098 0 4510 9753 0 0 1051 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7216 0 0 0 1322 0 744...

output:

447371303

result:

ok single line: '447371303'

Test #15:

score: 0
Accepted
time: 0ms
memory: 6764kb

input:

10000 9941
7366 0 5716 0 0 0 3313 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5032 0 0 0 9798 5273 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7219 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7601 0 5829 0 0 0 0 0 0 8965 0 1976 0 0 3206 0 0 0 0 671 0 0 6007 0 0 0 0 0 1387 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 532 0...

output:

261688908

result:

ok single line: '261688908'

Test #16:

score: 0
Accepted
time: 4ms
memory: 6708kb

input:

10000 9931
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 781 7289 3296 0 0 0 0 0 0 0 9404 0 0 5023 0 0 0 0 0 0 0 8172 0 0 5000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6920 0 0 0 0 5838 0 0 0 0 0 0 0 0 0 5885 0 9544 0 0 0 0 7872 0 0 0 0 0 1679 0 0 0 0 0 0 0 0 0 0 0 106 0 0 0 0 0 0 8737 0 5810 0 0 9649 0 0 0 0 48...

output:

874520150

result:

ok single line: '874520150'

Test #17:

score: 0
Accepted
time: 4ms
memory: 6764kb

input:

10000 9929
493 0 0 6598 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6957 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7714 0 9750 4820 0 0 0 8986 0 0 0 2028 8552 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2597 0 0 0 0 0 0 0 0 0 0 0 0 0 4825 0 0 0 0 2170 0 1920 0 0 0 0 4666 0 0 0 0 0 0 ...

output:

603051728

result:

ok single line: '603051728'

Test #18:

score: 0
Accepted
time: 4ms
memory: 7008kb

input:

10000 9923
4913 0 0 9854 0 0 1005 0 8129 0 0 0 0 0 0 0 0 0 0 7603 0 0 0 905 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8808 0 0 0 0 6992 0 7080 3659 0 0 0 0 5751 0 0 0 0 0 0 0 0 1909 0 0 0 0 2734 0 0 0 0 0 0 0 0 3275 0 0 0 0 0 0 0 0 8357 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 272 0 0 0 0 0 0 3...

output:

629438343

result:

ok single line: '629438343'

Test #19:

score: 0
Accepted
time: 4ms
memory: 6752kb

input:

10000 9907
0 0 0 0 0 0 0 0 5990 0 0 0 0 0 0 0 0 0 0 0 5447 0 0 0 0 0 0 7249 0 0 0 0 1765 0 4833 0 0 0 0 4903 0 0 0 0 0 0 0 0 0 8088 0 3322 0 0 0 0 0 0 7429 0 0 0 0 0 0 0 0 0 0 0 0 0 0 267 0 0 1356 0 0 1503 0 0 7970 0 0 0 6280 0 0 0 0 0 0 0 0 0 0 0 2887 0 0 0 5546 0 0 495 0 0 0 0 0 0 0 0 7033 0 0 0 0...

output:

941054716

result:

ok single line: '941054716'

Subtask #3:

score: 12
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #20:

score: 12
Accepted
time: 2ms
memory: 6752kb

input:

10000 9973
3686 0 0 0 3249 0 0 5133 0 0 0 0 2398 0 0 0 0 0 0 0 0 0 9880 0 0 0 0 0 0 0 0 9308 0 0 0 0 0 0 0 0 3993 0 0 0 0 0 0 0 0 6815 0 0 0 0 0 0 0 0 0 0 0 4954 5602 0 0 1729 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3673 0 5350 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7890 0 0 0 0 0 0 4035 0 0 0 0 0 0 0 0 0 ...

output:

520486781

result:

ok single line: '520486781'

Test #21:

score: 0
Accepted
time: 2ms
memory: 6768kb

input:

10000 9967
0 0 0 0 0 3540 935 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1314 0 9498 0 0 0 0 0 0 726 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6172 0 0 379 0 0 1547 1662 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 801 0 0 0 2046 0 0 0 0 0 0 0 0 3809 0 0 0 0 0 459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

284497295

result:

ok single line: '284497295'

Test #22:

score: 0
Accepted
time: 4ms
memory: 6764kb

input:

10000 9949
9744 8940 0 0 0 0 0 0 0 0 4050 0 0 0 0 0 4227 0 0 0 0 0 0 0 0 0 4661 0 0 8476 0 0 0 0 0 0 0 4126 0 0 0 0 0 0 0 0 1578 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6673 0 6720 0 0 0 0 0 0 0 0 0 0 0 5794 0 0 0 0 0 0 0 0 3066 0 6066 0 0 0 0 261 0 0 0 0 0 3419 0 0 0 8772 0 0 0 0 0 3478...

output:

903227414

result:

ok single line: '903227414'

Subtask #4:

score: 8
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #23:

score: 8
Accepted
time: 4ms
memory: 6748kb

input:

10000 9973
0 8619 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3627 0 0 5840 3918 0 0 0 0 0 1319 0 0 0 0 0 0 0 0 8317 0 0 0 0 0 0 3524 1297 0 0 0 4673 864 0 0 0 0 5895 0 0 0 0 0 0 0 0 0 0 0 0 4390 0 0 6610 5986 421 0 0 9554 0 0 0 0 0 0 0 0 0 959 9253 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4154 0 0 0 0 0 0 0...

output:

68617449

result:

ok single line: '68617449'

Test #24:

score: 0
Accepted
time: 4ms
memory: 6832kb

input:

10000 9967
0 0 0 0 3774 6437 0 0 0 7697 0 0 1002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7923 0 0 0 0 0 0 0 0 0 0 0 0 0 8332 0 8498 0 0 0 0 0 5784 0 0 0 0 0 0 0 9633 0 0 0 2936 0 0 0 0 0 0 0 0 6963 0 0 0 0 0 5986 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6017 0 3087 0 3972 0 0 0 0 0 0 7016 0 2393 0 0 6953 0 0 0 0 0 0 0 0...

output:

828095256

result:

ok single line: '828095256'

Subtask #5:

score: 4
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 4
Accepted
time: 23ms
memory: 8584kb

input:

100000 99817
0 0 0 0 0 0 0 0 32114 0 94022 0 74011 0 0 0 0 0 0 72729 43943 0 0 53641 0 0 93458 0 0 83410 0 0 0 0 36768 0 0 48557 0 0 0 56366 0 0 0 31003 0 0 0 0 0 0 0 0 0 4222 0 0 50438 0 0 0 0 0 0 0 0 0 64001 0 0 0 0 0 0 0 0 0 0 0 5186 0 0 14559 0 0 0 0 0 0 61305 0 55342 0 60870 65953 0 0 0 0 30398...

output:

82362512

result:

ok single line: '82362512'