Submission #1125768


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&res = used[i][j];
  auto& ans = dp[i][j];
  if ( res )return ans;
  res = 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 0
Code Size 4556 Byte
Status CE

Compile Error

./Main.cpp: In function ‘mint dfs(int, int)’:
./Main.cpp:105:23: error: invalid initialization of non-const reference of type ‘std::_Bit_reference&’ from an rvalue of type ‘std::vector<bool>::reference {aka std::_Bit_reference}’
   auto&res = used[i][j];
                       ^