ARC061 D - すぬけ君の塗り絵 / Snuke's Coloring

問題文
D - すぬけ君の塗り絵 / Snuke's Coloring

解き方
制約が大きいので与えられた時に次々と処理していくという方法以外無理そう。
3行3列の正方形に注目すると、それでうまくいくことがわかる。


やっぱちゃんと繋がるatcoder最高やなって

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
#define int long long
int h,w,n;

const int dx[9] = {1, 1, 1, 0, 0, -1, -1, -1,0};
const int dy[9] = {0, 1, -1, 1, -1, 0, 1, -1,0};
map<pair<int,int>,int> mp;
int ans[10];
signed main(){
  cin>>h>>w>>n;
  int cnt=0;

  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;

    for(int j=0;j<9;j++){
      int xt=a+dx[j];
      int yt=b+dy[j];
      if(1<=xt && 1<=yt &&xt<h-1&&yt<w-1){
        cnt++;
        mp[make_pair(xt,yt)]+=1;
      }
    }
  }
  for(auto itr:mp){
     ans[itr.second]++;
  }
  int total=0;
  for(int i=1;i<10;i++){
    total+=ans[i];
  }
  cout<<(h-2)*(w-2)-total<<endl;
  for(int i=1;i<10;i++){
    cout<<ans[i]<<endl;
  }
}

SRM504.5と508のdiv1easy

>|cpp|

string bs;
int n;

class MathContest {
public:
int countBlack(string ballSequence, int repetitions) {
rep(i,repetitions)bs+=ballSequence;

int turned=0;
int anticolor=0;
int idx=0,idx2=0,ans=0;
n=bs.size();
int indi=0;

while(1){

//cerr<<indi<<endl;

if*1{
anticolor+=1;
anticolor%=2;
ans++;
}else{
turned+=1;
turned%=2;
}
if(turned==1){
idx2++;
indi=n-idx2;
}
else {
idx++;
indi=idx;
}

if(idx+idx2==n)break;

}


return ans;
}
};

||<

>|cpp|

//nの素因数の数
int cost(int n){
int ret=0;
for(int i=2;i*i<=n;i++){
while(n%i==0){
ret++;
n/=i;
}
}
if(n!=1)ret++;
return ret;
}
class DivideAndShift {
public:
int getLeast(int N, int M) {
M--;
int ans=min(M,N-M);
for(int i=2;i<=N;i++){
if(N%i==0){
int m=M%(N/i);
ans=min(ans,cost(i)+min(N/i-m,m));
}
}
return ans;
}
};

||<

*1:anticolor==1 && bs[indi]=='W')||(anticolor==0 && bs[indi]=='B'