Submission #1125769


Source Code Expand

#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner
{
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for ( A&i : a ) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/


template<class T, class B, class...V>struct Vec
{
  typedef Vec<T, V...>A; typedef vector<typename A::t>t; t nvec(B a, V...b) { return t(a, A().nvec(b...)); }
};
template<class T, class B>struct Vec<T, B> { typedef vector<T>t; t nvec(B a) { return t(a); } };
template<class T>tuple<T>Init(T t) { return tuple<T>(t); }
template<class T, class C>struct Vec<T, tuple<C>> { using t = T; T nvec(tuple<C> a) { return get<0>(a); } };
template<class T = int, class...B> typename Vec<T, B...>::t nvec(B...b) { return Vec<T, B...>().nvec(b...); }



const ll mod = (ll)1e9 + 7;
template<ll MOD>struct Mint
{
  typedef const Mint&T;
  ll x = 0;
  Mint() {}
  Mint(ll a) { x = a % MOD; if ( x < 0 ) x += MOD; }
  Mint&operator+=(T a) { if ( (x += a.x) >= MOD ) x -= MOD; return *this; }
  Mint&operator-=(T a) { if ( (x += MOD - a.x) >= MOD ) x -= MOD; return *this; }
  Mint&operator*=(T a) { x = x * a.x % MOD; return *this; }
  Mint&operator/=(T a) { return *this *= a.Pow(MOD - 2); }
  Mint operator+(T a)const { return Mint(*this) += a; }
  Mint operator-(T a)const { return Mint(*this) -= a; }
  Mint operator*(T a)const { return Mint(*this) *= a; }
  Mint operator/(T a)const { return Mint(*this) /= a; }
  bool operator<(T a)const { return x < a.x; }
  bool operator==(T a)const { return x == a.x; }
  Mint Pow(ll k)const
  {
    if ( k == 0 ) return 1;
    Mint t = Pow(k / 2);
    return t *= (k & 1) ? t * *this : t;
  }
};
template<ll MOD>istream&operator >> (istream&i, Mint<MOD>&a) { return i >> a.x; }
template<ll MOD>ostream&operator<<(ostream&o, const Mint<MOD>&a) { return o << a.x; }
typedef Mint<mod>mint;

template<ll MOD = mod>Mint<MOD> CombMod(int n, int r)
{
  Mint<MOD> a = 1, b = 1;
  rep(i, r) { a *= (n - i); }
  rep(i, 2, r + 1) { b *= i; }
  err(a, b);
  return a / b;
}
struct XY
{
  int x, y;
  XY&operator+=(const XY&d) { x += d.x; y += d.y; return *this; }
  XY operator+(const XY&d)const { return XY(*this) += d; }
  bool operator==(const XY&d)const { return x == d.x && y == d.y; }
  bool check(int w, int h)const { return 0 <= x && x < w && 0 <= y && y < h; }
};
const XY d4[] = { { -1,0 }, { 1,0 }, { 0,-1 }, { 0,1 }, };
template<class T> auto get(T& a, XY d)->decltype(a[d.y][d.x]) { return a[d.y][d.x]; }
ostream& operator<<(ostream& os, XY d) { return os << '(' << d.x << ',' << d.y << ')'; }


int h, w;

vector<vector<mint>> dp;
vector<vector<bool>> used;

vector<vector<int>> v;
mint dfs(int i, int j)
{
  auto& ans = dp[i][j];
  if ( used[i][j] )return ans;
  used[i][j] = true;

  for ( auto& t : d4 )
  {
    auto x = t.x + j;
    auto y = t.y + i;

    if ( 0 <= y && y < h && 0 <= x && x < w )
    {
      if ( v[i][j] < v[y][x] )
        ans += dfs(y, x)+1;

    }
  }
  return ans;
}
void Calc()
{
  in, h, w;
  v.resize(h);
  for ( auto& i : v )
  {
    i = in.Array(w);
  }
  err(h, w);

  used = nvec<bool>(h, w, Init(false));
  dp = nvec<mint>(h, w);


  mint ans = 0;
  rep(i, h)rep(j, w)
  {
    ans += dfs(i, j);
  }
  cout << (ans+h*w) << endl;


}

Submission Info

Submission Time
Task D - 経路
User oigami
Language C++14 (GCC 5.4.1)
Score 100
Code Size 4544 Byte
Status AC
Exec Time 148 ms
Memory 74240 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
Set Name Test Cases
sample sample01.txt, sample02.txt
All 00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample01.txt, sample02.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
00.txt AC 134 ms 12416 KB
01.txt AC 144 ms 74240 KB
02.txt AC 86 ms 12160 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 2 ms 256 KB
11.txt AC 146 ms 12288 KB
12.txt AC 146 ms 12288 KB
13.txt AC 147 ms 12288 KB
14.txt AC 146 ms 12288 KB
15.txt AC 133 ms 12416 KB
16.txt AC 148 ms 12288 KB
17.txt AC 146 ms 12288 KB
18.txt AC 95 ms 12288 KB
19.txt AC 78 ms 12288 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB