Skip to content

Commit 0c9e73e

Browse files
committed
gcj14 qual C.cpp
1 parent a2e0e93 commit 0c9e73e

File tree

1 file changed

+14
-56
lines changed

1 file changed

+14
-56
lines changed

GCJ/14/Qual/C.cpp

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
#include <iostream>
2-
#include <sstream>
3-
#include <string>
42
#include <cstring>
5-
#include <cstdio>
6-
#include <vector>
7-
#include <deque>
8-
#include <map>
9-
#include <algorithm>
103
using namespace std;
114

125
#define REP(i,n) for(int i=0;i<(n);++i)
136
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
147
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
15-
typedef long long LL;
168

17-
int mm[55][55];
18-
int R, C, M, S;
19-
bool rotate;
9+
int mm[55][55], R, C, M, S, rotate;
2010

2111
char convert(int val) {
2212
if (val == -1) return 'c';
@@ -25,24 +15,19 @@ char convert(int val) {
2515
}
2616

2717
void setValues(int val) {
28-
REP(i,55) {
29-
REP(j,55) mm[i][j] = val;
30-
}
18+
REP(i,55) REP(j,55) mm[i][j] = val;
3119
}
3220

33-
void print(bool rotate) {
34-
if (rotate) {
21+
void print(int rotate) {
22+
mm[0][0] = -1;
23+
if (rotate == 1) {
3524
REP(i,C) {
36-
REP(j,R) {
37-
cout << convert(mm[j][i]);
38-
}
25+
REP(j,R) cout << convert(mm[j][i]);
3926
cout << endl;
4027
}
4128
} else {
4229
REP(i,R) {
43-
REP(j,C) {
44-
cout << convert(mm[i][j]);
45-
}
30+
REP(j,C) cout << convert(mm[i][j]);
4631
cout << endl;
4732
}
4833
}
@@ -51,93 +36,66 @@ void print(bool rotate) {
5136
void run() {
5237
cin >> R >> C >> M;
5338
S = R * C - M;
54-
5539
if (M == 0) {
5640
memset(mm, 0, sizeof(mm));
57-
mm[0][0] = -1;
58-
print(false);
41+
print(0);
5942
return;
6043
}
61-
6244
if (S == 1) {
6345
setValues(1);
64-
mm[0][0] = -1;
65-
print(false);
46+
print(0);
6647
return;
6748
}
6849

69-
bool rotate = false;
50+
int rotate = 0;
7051
if (R > C) {
7152
swap(R, C);
72-
rotate = true;
53+
rotate = 1;
7354
}
74-
7555
if (R == 1) {
7656
setValues(1);
7757
REP(i,S) mm[0][i] = 0;
78-
mm[0][0] = -1;
7958
print(rotate);
8059
return;
8160
}
82-
8361
if (R == 2) {
84-
if (S & 1) cout << "Impossible" << endl;
85-
else if (S < 4) cout << "Impossible" << endl;
62+
if ((S & 1) || (S < 4)) cout << "Impossible" << endl;
8663
else {
8764
setValues(1);
8865
REP(i,S/2) mm[0][i] = mm[1][i] = 0;
89-
mm[0][0] = -1;
9066
print(rotate);
9167
}
9268
return;
9369
}
9470

95-
if (S <= 3) {
96-
cout << "Impossible" << endl;
97-
return;
98-
}
99-
10071
RFOR(p,C,2) {
10172
if (p * R < S) break;
102-
10373
int rest = S - p * 2;
104-
10574
setValues(1);
10675
REP(i,p) mm[0][i] = mm[1][i] = 0;
10776

10877
if (rest == 0) {
109-
mm[0][0] = -1;
11078
print(rotate);
11179
return;
11280
}
113-
11481
if (rest <= 1) continue;
11582

11683
int r = R - 2;
11784
int num = rest / r;
11885
if (num >= 2) {
119-
REP(i,r) {
120-
REP(j,num) {
121-
mm[2 + i][j] = 0;
122-
}
123-
}
86+
REP(i,r) REP(j,num) mm[2 + i][j] = 0;
12487
rest -= num * r;
125-
REP(i,rest) {
126-
mm[2 + i][num] = 0;
127-
}
88+
REP(i,rest) mm[2 + i][num] = 0;
12889
} else {
12990
REP(i,(rest/2)) mm[2 + i][0] = mm[2 + i][1] = 0;
13091
if (rest & 1) {
13192
if (2 >= p) continue;
13293
else mm[2][2] = 0;
13394
}
13495
}
135-
mm[0][0] = -1;
13696
print(rotate);
137-
13897
return;
13998
}
140-
14199
cout << "Impossible" << endl;
142100
}
143101

0 commit comments

Comments
 (0)