QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642050 | #8935. Puzzle: Easy as Scrabble | ucup-team3215 | WA | 16ms | 5612kb | C++23 | 3.4kb | 2024-10-15 09:18:42 | 2024-10-15 09:18:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<char> L(n), R(n), U(m), D(m);
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i <= n + 1; ++i) {
for (int j = 0; j <= m + 1; ++j) {
char c;
cin >> c;
if (i >= 1 && i <= n && j >= 1 && j <= m) {
a[i - 1][j - 1] = c;
} else if (!i) {
if (j >= 1 && j <= m)U[j - 1] = c == '.' ? 0 : c;
} else if (i == n + 1) {
if (j >= 1 && j <= m)D[j - 1] = c == '.' ? 0 : c;
} else if (!j) {
if (i >= 1 && i <= n)L[i - 1] = c == '.' ? 0 : c;
} else if (j == m + 1) {
if (i >= 1 && i <= n)R[i - 1] = c == '.' ? 0 : c;
}
}
}
auto letthemend = [] {
cout << "NO\n";
exit(0);
};
vector<vector<char>> res(n, vector<char>(m, '.'));
vector<int> l(n), r(n, m - 1), u(m), d(m, n - 1);
for (int i = 0; i < n; ++i) {
if (L[i])while (l[i] < m && a[i][l[i]] == 'x')++l[i];
else l[i] = -1;
if (R[i])while (r[i] >= 0 && a[i][r[i]] == 'x')--r[i];
else r[i] = m;
}
queue<int> q;
for (int j = 0; j < m; ++j)q.push(j);
for (int j = m - 1; ~j; --j)q.push(j);
while (q.size()) {
int j = q.front();
q.pop();
if (j < 0 || j >= m)continue;
if (U[j]) {
for (; u[j] < n; ++u[j]) {
if (a[u[j]][j] == 'x' || l[u[j]] > j)continue;
if (l[u[j]] < j || L[u[j]] == U[j])break;
++l[u[j]];
while (l[u[j]] < m && a[u[j]][l[u[j]]] == 'x')++l[u[j]];
q.push(l[u[j]]);
}
}
if (D[j]) {
for (; ~d[j]; --d[j]) {
if (a[d[j]][j] == 'x' || l[d[j]] > j)continue;
if (l[d[j]] < j || L[d[j]] == D[j])break;
++l[d[j]];
while (l[d[j]] < m && a[d[j]][l[d[j]]] == 'x')++l[d[j]];
q.push(l[d[j]]);
}
}
if (U[j]) {
for (; u[j] < n; ++u[j]) {
if (a[u[j]][j] == 'x' || r[u[j]] < j)continue;
if (r[u[j]] > j || R[u[j]] == U[j])break;
--r[u[j]];
while (r[u[j]] >= 0 && a[u[j]][r[u[j]]] == 'x')--r[u[j]];
q.push(r[u[j]]);
}
}
if (D[j]) {
for (; ~d[j]; --d[j]) {
if (a[d[j]][j] == 'x' || r[d[j]] < j)continue;
if (r[d[j]] > j || R[d[j]] == D[j])break;
--r[d[j]];
while (r[d[j]] >= 0 && a[d[j]][r[d[j]]] == 'x')--r[d[j]];
q.push(r[d[j]]);
}
}
}
for (int j = 0; j < m; ++j)if (u[j] > d[j] || (u[j] == d[j] && U[j] != D[j]))letthemend();
for (int i = 0; i < n; ++i)if (l[i] > r[i] || (l[i] == r[i] && L[i] != R[i]))letthemend();
for (int i = 0; i < n; ++i) {
if (L[i])res[i][l[i]] = L[i];
if (R[i])res[i][r[i]] = R[i];
}
for (int j = 0; j < m; ++j) {
if (U[j])res[u[j]][j] = U[j];
if (D[j])res[d[j]][j] = D[j];
}
cout << "YES\n";
for (auto &i: res) {
for (auto &j: i)cout << j;
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
5 5 .CBA... ....x.. ..x...C A.....B B..x..A C...... .......
output:
YES CBA.. ....C A...B B...A C....
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
5 5 .U.N.X. U....xX Ox....X M...xxN Vx....S Ix.x..X ..IBHX.
output:
YES U.NX. .O..X M.N.. .VB.S .I.HX
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
10 10 .BAZEMIEKUJ. A..........K B..x.x.x..x. K.........xT A.x..x.....J Hx....x....B Q..x....x.xW S...x......W S...x.xxx..Z ...x......xZ I..x..x.x.xR .QKO.ID..RW.
output:
YES .AZEMIEK.. B.......U. K.......T. A........J .H.......B Q.......W. S........W S.O.....Z. QK...D..Z. ...II...R.
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
5 10 .PTWIVVISPY. T...x.x....Y Xx.x.xx..x.K P.x.xx.....K S..........A E.........xS .SPEASDCYSA.
output:
YES .TW.V.ISPY .X.I.....K P....V...K SP.......A ..EASDCYS.
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
10 5 .HVYN.. Y.x...C V..x..B H...x.Z ....xxN ....x.P B.x...G Fx.x..D Txx..xK E..x.xR Sx....B .EPSBD.
output:
YES ..YNC .V..B H...Z ..N.. ....P B...G .F..D ..TK. EP.R. ..SB.
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
50 50 .YDOGQIDENEUMONVSGZNMNHLEZCXIRMK.OOCKJOKXXZDUFEMPXS. Y.x...x.x.x..x..........x.......x......x.....x....xX N.........x.....x.....x....x.x.xxxxx.x...x.........E U.....x.....x....x......x.....x........x..........xS ...x......x........x..x.....x.x.x........x.x.x.....S Q.....x.x..x..........x....x....
output:
YES Y.OGQ.D.N.UM.NVSGZNMNHL.ZCXIRMK.OOCKJO.XXZDU.EMPX. ND...I.E....O..........E..............K.....F...E. U........E......................................S. .................................................S Q................................................L F...........................................
result:
ok Correct.
Test #8:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
100 100 .NUXAMX.LNWZKRRKZIRNZVDJF.XRB.VEFQXHTGLGIKZYSRPPF.YGVTOSQCADEG.KYKH.NWWO.XDXJW.G.RBHABFLWHFVUNOLBHMKN. U..x...x...x....xx........x.....x.....xxx..x..........x..x...x..xx..x..x..x............x.....x.....x.N C...x.......x.............x....x.x.x..x........x..x.xx..x..xx.................x..........
output:
YES .U.AMX.LNW.KRRK..RNZVDJF..RB.VE.QXHTG...KZ.SRPPF.YGVT.SQ.ADE..K..H..WW..X.XJW.G.RBHABF.WHFVU.OLBHM.N .CX.......Z....ZI..............F......GI..Y..........O..C...G..YK..N..O..D..................N.....KO .O...................................L...........................................................
result:
ok Correct.
Test #9:
score: 0
Accepted
time: 4ms
memory: 4140kb
input:
500 500 ..FHFDLGFGHREQBGILNRAGJ.ERZSAFGLQ.ESEBI.ELKM.RENLNFQSPT.TXUEIKHHOQWABSELMOPGTFGTXGYMTSU.N.O.AX.OGNSWTFSLUIMTUX.RUCECKZCXOJNPTFVAJUJTF.LHXURYIQIJCVWDBVZ.ZXFRAT.XIPXTDCSLHJHSZCW.RMNUGPIHYUQYUYAY.NHCBU.JPMLG.DDXAJWKNZJVKNAWAJZAHW.FCBEVATZ.YZ.HQ..QPLFARSHNP..EDPIKLYLF.FIFXEXR.XSUORAP.CZPMJXPUS.W...
output:
YES ...FDL...HREQ..ILNRA...ERZSA.GL...SE.I..LK...ENLNFQS.T.TX.E.K.HOQWA.SE.M.PGTFG.XGY..SU...O.AX.OGNS.TFSLUIM.UX...CEC..CXOJNPT.VA..JTF.LHXURYIQI.CVWDB.Z..XFR.T..IPXTD..LHJHSZCW.RMNUGPIHYUQY.YA..N.CB..JPM.G.DD.AJW.NZJ...AWAJZAHW.FCB...T..YZ.HQ..Q.LFA.S.NP..EDPI.LYLF..IFXEX...SUO.AP.CZP.JXPUS.W.D.WU...
result:
ok Correct.
Test #10:
score: 0
Accepted
time: 16ms
memory: 5612kb
input:
1000 1000 .SKFDQ.AV.GPTHMF.PL.YOQRQOXDOF.XVZ.H.MYOJIYT.QZNJQI.ZZMAJ.OAWBJBRXFW.CLEPPKGGAWGTVBKOBL.GPCO.ML.DBL.A.RJ..GF.EHK.CDXLLTCBCL.CGYJBMUSPIN.QELGYW.JE..CFVQF.LVYLFHYJ.MY.FZ.RU.ODLAYTWIZQOQZXBW.BVD.RFPLHLEHAU.G.PLFWFUKA.RSG..AVU.SA.PWRGJYO.OXD..S.Z.LIIADT.YXH..NHWXY.R.YFLS.URIJGPPURZPPVHJFLMKTDT...
output:
YES S.FDQ.AV.GPTHMF.P..YOQRQOXD.F.XV.....YO.IYT.QZ.JQI.ZZMAJ.OAWBJBRX...C.EPP.GGAWGT.B..BL.GPCO.ML.D.L.A.R...GF.E.K.CDXLLT.BCL.CGYJB.USPIN..EL..W.J...CFVQ..LV.LFHYJ.MY.FZ.R..ODLAYTWIZQO.ZX.W...D.R..LHLE.A..G.PLFWFUKA.R.G..A...SA..WRGJ...OXD....Z.L.I.DT.Y.H..N.WXY.R.Y.LS..RI.G.PU.ZP.V..FLMKT.TWI.ZKHZ...
result:
ok Correct.
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
1 1000 .K.CCS...LC.....Y..J...E.W.B..Q..KQ...Q...L..U.XSWX..NB..K.OLF...Y.A....HG....RRQO..Y...J.LOS...IN..C......H......X.....B.B.PQRT....VB.........P...E....MF.E...RH.XADCQN.D.KT.W..XNI..PH.Q.L.H..G...ZJR.V.I.......O......J.X..N..QS......UN....HLS..Z..N....X.YH.W..E.Z..JHSAV......YXT.P..TX.WT.SHE....
output:
NO
result:
wrong answer Jury has answer but participant has not.