Submission #1188999
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
typedef long long ll;
typedef pair<int,int> p;
int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};
int H, W, K;
string field[60];
int used[60][60];
struct node {
int y, x, spec;
bool operator<( const node& r ) const {
return spec < r.spec;
}
};
bool isOk(vector<vector<int> > &tmp_used, node n) {
// 範囲外
if (n.x < 0 || W <= n.x || n.y < 0 || H < n.y) {
return false;
}
// 使用された or 数字がゼロ
if (tmp_used[n.y][n.x] || used[n.y][n.x] || field[n.y][n.x]=='0') {
return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin >> H >> W >> K;
priority_queue<node> q;
REP(i, H) {
cin >> field[i];
REP(j, W) q.push(node{(int)i,(int)j,field[i][j]-'0'});
}
vector< set<node> > lans;
while(!q.empty()) {
node a = q.top();q.pop();
if (used[a.y][a.x]) continue;
set<node> ans;
ans.insert(a);
vector<vector<int> > tmp_used(60,vector<int>(60,0));
while(ans.size()!=K) {
node add_node = {-1,-1,0};
for (node b: ans) {
REP(i,4) {
int nx = b.x + dx[i];
int ny = b.y + dy[i];
if (isOk(tmp_used,node{ny,nx,0})){
node tnode = node{ny,nx,field[ny][nx]-'0'};
if (add_node < tnode) {
add_node = tnode;
}
}
}
}
if (add_node.y==-1) break;
ans.insert(add_node);
tmp_used[add_node.y][add_node.x] = 1;
}
if (ans.size()==K) {
for (node b: ans) {
used[b.y][b.x] = 1;
}
lans.pb(ans);
}
}
cout << lans.size() << endl;
for (set<node> &sn: lans) {
for (node n: sn) {
cout << n.y+1 << " " << n.x+1 << endl;
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Multiple Pieces |
User |
yush1ga |
Language |
C++14 (GCC 5.4.1) |
Score |
22375 |
Code Size |
2360 Byte |
Status |
AC |
Exec Time |
17 ms |
Memory |
384 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 |
2145 / 1343058 |
2501 / 1343058 |
2287 / 1343058 |
2301 / 1343058 |
2397 / 1343058 |
2229 / 1343058 |
2107 / 1343058 |
2123 / 1343058 |
1980 / 1343058 |
2305 / 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 |
16 ms |
384 KB |
subtask_01_02.txt |
AC |
16 ms |
384 KB |
subtask_01_03.txt |
AC |
16 ms |
384 KB |
subtask_01_04.txt |
AC |
16 ms |
384 KB |
subtask_01_05.txt |
AC |
16 ms |
384 KB |
subtask_01_06.txt |
AC |
16 ms |
384 KB |
subtask_01_07.txt |
AC |
16 ms |
384 KB |
subtask_01_08.txt |
AC |
17 ms |
384 KB |
subtask_01_09.txt |
AC |
16 ms |
384 KB |
subtask_01_10.txt |
AC |
16 ms |
384 KB |