Submission #2086923
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
int mp[51][51];
bool used[51][51];
vector<pint> v[500];
const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int main(){
int h,w,k;
cin>>h>>w>>k;
int cnt=0;
string si;
rep(i,h){
cin>>si;
rep(j,w) mp[i][j]=si[j]-'0';
}
rep(y,h)rep(x,w){
if(used[y][x]&&mp[y][x]==0) continue;
queue<pair<pint,int> > q;
q.push({{x,y},0});
used[y][x]=true;
while(!q.empty()){
pair<pint,int> pi=q.front();q.pop();
int mx=0,nx=-1,ny=-1;
rep(i,4){
int tx=pi.first.first+dx[i],ty=pi.first.second+dy[i];
if(tx>=0&&ty>=0&&tx<w&&ty<h&&mp[ty][tx]!=0&&!used[ty][tx]){
if(mx<mp[ty][tx]) mx=mp[ty][tx],nx=tx,ny=ty;
}
}
if(mx==0){
for(auto it:v[cnt]){
used[it.second][it.first]=false;
}
v[cnt].clear();
break;
}
q.push({{nx,ny},pi.second+1});
v[cnt].pb(nx,ny);
used[ny][nx]=true;
if(v[cnt].size()==k){
++cnt;
break;
}
}
}
cout<<cnt<<endl;
rep(i,cnt){
rep(j,k){
cout<<v[i][j].second+1<<" "<<v[i][j].first+1<<endl;
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Multiple Pieces |
User |
ts_ |
Language |
C++14 (GCC 5.4.1) |
Score |
185852 |
Code Size |
1604 Byte |
Status |
AC |
Exec Time |
6 ms |
Memory |
256 KB |
Judge Result
Set Name |
test_01 |
test_02 |
test_03 |
test_04 |
test_05 |
test_06 |
test_07 |
test_08 |
test_09 |
test_10 |
Score / Max Score |
17559 / 1343058 |
17319 / 1343058 |
20335 / 1343058 |
16151 / 1343058 |
22277 / 1343058 |
17126 / 1343058 |
17764 / 1343058 |
14699 / 1343058 |
19548 / 1343058 |
23074 / 1343058 |
Status |
|
|
|
|
|
|
|
|
|
|
Set Name |
Test Cases |
test_01 |
subtask_01_01.txt |
test_02 |
subtask_01_02.txt |
test_03 |
subtask_01_03.txt |
test_04 |
subtask_01_04.txt |
test_05 |
subtask_01_05.txt |
test_06 |
subtask_01_06.txt |
test_07 |
subtask_01_07.txt |
test_08 |
subtask_01_08.txt |
test_09 |
subtask_01_09.txt |
test_10 |
subtask_01_10.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask_01_01.txt |
AC |
5 ms |
256 KB |
subtask_01_02.txt |
AC |
5 ms |
256 KB |
subtask_01_03.txt |
AC |
5 ms |
256 KB |
subtask_01_04.txt |
AC |
6 ms |
256 KB |
subtask_01_05.txt |
AC |
5 ms |
256 KB |
subtask_01_06.txt |
AC |
5 ms |
256 KB |
subtask_01_07.txt |
AC |
5 ms |
256 KB |
subtask_01_08.txt |
AC |
5 ms |
256 KB |
subtask_01_09.txt |
AC |
5 ms |
256 KB |
subtask_01_10.txt |
AC |
5 ms |
256 KB |