結果

問題 No.226 0-1パズル
ユーザー ytqm3ytqm3
提出日時 2022-10-09 15:26:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 3,069 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 209,488 KB
最終ジャッジ日時 2025-02-08 00:43:53
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:125:15: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘u64’ {aka ‘long long unsigned int’} [-Wformat=]
  125 |      printf("%d\n", ((mint(2)^h[2])*(h[0]?0:1)+(mint(2)^w[2])*(w[0]?0:1)-check(tmp)).val);
      |              ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |               |                                                                      |
      |               int                                                                    u64 {aka long long unsigned int}
      |              %lld
main.cpp:80:11: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |      scanf("%d%d", &n, &m);
      |      ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using u64 = unsigned long long;
using i64 = long long;

template<u64 mod=998244353> struct modint{
  u64 val;
  modint(i64 val_=0):val((val_%i64(mod)+i64(mod))%i64(mod)){}
  modint operator-(){
    return (val==0)?0:mod-val;
  }
  modint operator+(modint rhs){
    return modint(*this)+=rhs;
  }
  modint operator-(modint rhs){
    return modint(*this)-=rhs;
  }
  modint operator*(modint rhs){
    return modint(*this)*=rhs;
  }
  modint operator/(modint rhs){
    return modint(*this)/=rhs;
  }
  modint operator^(i64 rhs){
    return modint(*this)^=rhs;
  }
  modint &operator+=(modint rhs){
    val+=rhs.val,val-=((val>=mod)?mod:0);
    return (*this);
  }
  modint &operator-=(modint rhs){
    val+=((val<rhs.val)?mod:0),val-=rhs.val;
    return (*this);
  }
  modint &operator*=(modint rhs){
    val=val*rhs.val%mod;
    return (*this);
  }
  modint &operator/=(modint rhs){
    return (*this)*=rhs^(mod-2);
  }
  modint &operator^=(i64 rhs){
    modint res=1,now=(*this);
    while(rhs){
      res*=((rhs&1)?now:1),now*=now,rhs>>=1;
    }
    return (*this)=res;
  }
  bool operator==(modint rhs){
    return val==rhs.val;
  }
  bool operator!=(modint rhs){
    return val!=rhs.val;
  }
  friend std::ostream &operator<<(std::ostream& os,modint x){
    return os<<(x.val);
  }
  friend std::istream &operator>>(std::istream& is,modint& x){
    u64 t;
    is>>t,x=t;
    return is;
  }
};

int check(array<int,2>& a){
     if(a[0]+a[1]==0){
          return 2;
     }
     if(a[0] && a[1]){
          return 0;
     }
     return 1;
}

int main(){
     constexpr u64 mod = 1000000007;
     typedef modint<mod> mint;
     int n,m;
     array<int,2> tmp({0,0});
     scanf("%d%d", &n, &m);
     vector<string> S(n);
     for(int i=0;i<n;++i){ cin>>S[i]; }
     vector<int> h(3),w(3);
     h[2]=n,w[2]=m;
     vector<map<int,int>> mph(n+1),mpw(m+1);
     vector<array<int,2>> sth(n+1,{0,0}),stw(m+1,{0,0});
     //mph[x] -> y : t + 1
     for(int i=0;i<n*m;++i){
          int x, y, t;
          x=i/m,y=i%m;
          if(S[x][y]=='?'){ continue; }
          t=S[x][y]-'0';
          if(mph[x][y]){
               h[check(sth[x])]--;
               int s=mph[x][y];
               mph[x][y]=0;
               sth[x][(y+s)%2]--;
               tmp[(x+y+s)%2]--;
               h[check(sth[x])]++;
          }
          if(mpw[y][x]){
               w[check(stw[y])]--;
               int s=mpw[y][x];
               mpw[y][x]=0;
               stw[y][(x+s)%2]--;
               w[check(stw[y])]++;
          }
          if(t==-1){
               continue;
          }
          {
               h[check(sth[x])]--;
               mph[x][y]=t+1;
               sth[x][(y+t+1)%2]++;
               tmp[(x+y+t+1)%2]++;
               h[check(sth[x])]++;
          }
          {
               w[check(stw[y])]--;
               mpw[y][x]=t+1;
               stw[y][(x+t+1)%2]++;
               w[check(stw[y])]++;
          }
     }
     printf("%d\n", ((mint(2)^h[2])*(h[0]?0:1)+(mint(2)^w[2])*(w[0]?0:1)-check(tmp)).val);
}
0