Submission #24453788
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>l_l;
vector<string>s;
ll answer=0;
ll n;
vector<ll> dx={1,0,-1,0};
vector<ll> dy={0,1,0,-1};
bool valid(ll x,ll y){
return 0<=x && x<=n-1 && 0<=y && y<=n-1;
}
void dfs(ll num){
if(num==0){
answer++;
return;
}
vector<l_l>next;
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
if(s[i][j]=='.'){
bool flag=false;
for(int z=0;z<=3;z++){
ll nxt_i=i+dx[z];
ll nxt_j=j+dy[z];
if(valid(nxt_i,nxt_j) && s[nxt_i][nxt_j]=='@'){
flag=true;
}
}
if(flag){
s[i][j]='@';
dfs(num-1);
s[i][j]='#';
next.push_back({i,j});
}
}
}
}
for(l_l pos:next){
s[pos.first][pos.second]='.';
}
}
signed main(){
ll k;cin>>n>>k;
s.resize(n);
for(int i=0;i<=n-1;i++)cin>>s[i];
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
if(s[i][j]=='.'){
s[i][j]='@';
dfs(k-1);
s[i][j]='#';
}
}
}
cout<<answer<<endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Red Polyomino |
| User | sugarrr |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1431 Byte |
| Status | AC |
| Exec Time | 25 ms |
| Memory | 3632 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 5 ms | 3592 KiB |
| 001.txt | AC | 2 ms | 3596 KiB |
| 002.txt | AC | 2 ms | 3552 KiB |
| 003.txt | AC | 2 ms | 3448 KiB |
| 004.txt | AC | 2 ms | 3472 KiB |
| 005.txt | AC | 2 ms | 3488 KiB |
| 006.txt | AC | 2 ms | 3440 KiB |
| 007.txt | AC | 1 ms | 3428 KiB |
| 008.txt | AC | 2 ms | 3604 KiB |
| 009.txt | AC | 2 ms | 3556 KiB |
| 010.txt | AC | 2 ms | 3524 KiB |
| 011.txt | AC | 2 ms | 3496 KiB |
| 012.txt | AC | 15 ms | 3600 KiB |
| 013.txt | AC | 15 ms | 3500 KiB |
| 014.txt | AC | 2 ms | 3424 KiB |
| 015.txt | AC | 3 ms | 3440 KiB |
| 016.txt | AC | 2 ms | 3600 KiB |
| 017.txt | AC | 2 ms | 3632 KiB |
| 018.txt | AC | 20 ms | 3608 KiB |
| 019.txt | AC | 25 ms | 3496 KiB |
| 020.txt | AC | 22 ms | 3420 KiB |
| 021.txt | AC | 17 ms | 3632 KiB |
| 022.txt | AC | 3 ms | 3492 KiB |
| 023.txt | AC | 2 ms | 3472 KiB |
| 024.txt | AC | 2 ms | 3416 KiB |
| 025.txt | AC | 2 ms | 3552 KiB |
| 026.txt | AC | 3 ms | 3528 KiB |
| 027.txt | AC | 2 ms | 3596 KiB |
| 028.txt | AC | 18 ms | 3600 KiB |
| example0.txt | AC | 2 ms | 3552 KiB |
| example1.txt | AC | 2 ms | 3524 KiB |
| example2.txt | AC | 20 ms | 3496 KiB |