QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608375 | #6115. Blocks and Expressions | qtoq# | AC ✓ | 1ms | 3828kb | C++23 | 3.1kb | 2024-10-03 21:17:25 | 2024-10-03 21:17:25 |
Judging History
answer
//thatsramen
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> bool mins(T& x, T y) { if (x > y) { x = y; return true; } return false; }
template<typename T> bool maxs(T& x, T y) { if (x < y) { x = y; return true; } return false; }
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set
void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
unsyncIO(); setPrec();
if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}
// #define TEST_CASES
void solve() {
int h, w;
cin >> h >> w;
vector<string> g(h);
for (int i = 0; i < h; i++) {
cin >> g[i];
}
function<ll(int, int, int)> go = [&](int row, int l, int r) -> ll {
for (int i = l; i <= r; i++) {
char x = g[row][i];
if (x != '.') {
if ('0' <= x && x <= '9') {
return x - '0';
} else {
if (x == '+') {
return go(row + 1, l, i - 1) + go(row + 1, i + 1, r);
} else if (x == '-') {
return go(row + 1, l, i - 1) - go(row + 1, i + 1, r);
} else {
return go(row + 1, l, i - 1) * go(row + 1, i + 1, r);
}
}
}
}
};
cout << go(0, 0, w - 1);
}
int main() {
setIO();
int tt = 1;
#ifdef TEST_CASES
cin >> tt;
#endif
while (tt--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
1 1 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
2 3 .-. 9.2
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
4 9 ...*..... .-.....+. 9.4..*..5 ....7.2..
output:
95
result:
ok 1 number(s): "95"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
9 35 ...............................+... ...........*.....................*. .+.....................+........8.6 5........+...........-...+......... .......*..1........*..0.0....*..... ...+....5....*......8......+..9.... ..5..+......2..+..........4.9...... ....5.9.......7..*................. ..........
output:
34489
result:
ok 1 number(s): "34489"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
9 31 .....................+......... .................+.....+....... ...-...............*..2..-..... .+.....*..........7.3...7....+. 4.1..-.........-...........*..5 ....0.5......*..2.........8.8.. ...........*..8................ .........+..2.................. ........2.5....................
output:
516
result:
ok 1 number(s): "516"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
7 29 ...........+................. .......-.................*... ...*.....-.......+.........+. .-...*..0.2....*...*......8.2 5.7.2.1......-..1.2..-....... ............8.3.....8..*..... ......................3.1....
output:
148
result:
ok 1 number(s): "148"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 13 ...........-. .....+......8 .*.....*..... 0..+..0..+... ..8.2...0.6..
output:
-8
result:
ok 1 number(s): "-8"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
7 21 .......+............. .-.......*........... 4....-..5..........+. ...+..1....*........6 ..8.0.....2....+..... .............+...+... ............0.8.9.1..
output:
207
result:
ok 1 number(s): "207"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
5 13 .........*... ...-.......+. .*.....+..2.4 9.5..+..0.... ....6.1......
output:
228
result:
ok 1 number(s): "228"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
7 29 .................-........... ...........*.......-......... .......+.......+..7........-. .*.......*...-..1........+..1 0..-....6.0.7.6........-..1.. ..5..*...............-..1.... ....9.0.............4.8......
output:
-12
result:
ok 1 number(s): "-12"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
9 37 .....................*............... ...................*.......+......... ...........-........5..-...........+. .........+.....+......3..+.....*....5 .+........7..-...+......1.4..-...-... 2......*....9.3.3.1.........2.8.2.2.. .....+..8............................ ...+..6.........................
output:
1185
result:
ok 1 number(s): "1185"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
9 23 .-..................... 3..+................... ..3..............-..... .....+...............+. ....9..+...........-..8 ......4......*....9.5.. ...........+...+....... .........+..7.3.1...... ........4.9............
output:
-81
result:
ok 1 number(s): "-81"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
12 37 .................................+... ...............................*...+. ...........................-....5.0.1 .........................+...*....... ...................+......6.5.9...... ...+.................*............... .*.....+............7..*............. 4.4..-...........*....1.8......
output:
371
result:
ok 1 number(s): "371"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 5 ...+. .*..2 9.3..
output:
29
result:
ok 1 number(s): "29"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
6 15 .*............. 0....*......... ...+.....*..... ..7.0..-...+... ......5.8.5..-. ............7.5
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
5 11 .........+. .....+....7 .-.....+... 8..-..1.6.. ..3.4......
output:
23
result:
ok 1 number(s): "23"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
8 23 .+..................... 4....................+. .......-..............4 .....*.....+........... ...+..3..-.........-... ..5.9...4.1....-....5.. .............-...+..... ............5.1.8.3....
output:
59
result:
ok 1 number(s): "59"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
9 23 .*..................... 9....................+. ...................*..6 .......-............1.. .....+.....*........... ...+..8..+...-......... ..6.0...1.1.4....+..... ...............*..9.... ..............1.0......
output:
270
result:
ok 1 number(s): "270"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 3 .-. 8.4
output:
4
result:
ok 1 number(s): "4"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
5 13 ...-......... .*.......+... 0.4....+...-. .....+..6.8.1 ....4.8......
output:
-25
result:
ok 1 number(s): "-25"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
6 33 .................+............... .....+.....................*..... ...+.......+...........-.....+... .-..4..*.......*.....-...-..7..-. 0.9...4..+...-..7..*..1.9.1...4.6 ........9.4.7.5...2.8............
output:
96
result:
ok 1 number(s): "96"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
7 29 ...............+............. .........+.............+..... .-.........-.........*.....-. 5..*......7..*.....-..4..-..9 ..5..+......3.7..+..9...6.6.. ....1..+........0.0.......... ......2.1....................
output:
-74
result:
ok 1 number(s): "-74"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 17 ...*............. .-.........-..... 0.1......+.....-. .....*....0..-..4 ....0..-....9.9.. ......0.6........
output:
-4
result:
ok 1 number(s): "-4"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
6 33 ...............*................. .......+.................*....... .+.......+...........+.....*..... 7..*....6..-.......*...-..8..+... ..3..-....0..-...+..3.8.4...2..-. ....7.4.....7.2.7.8...........6.8
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
6 27 .............*............. .....+...............+..... .-.....*.......+.........+. 2..+..8....*..4..-.....+..0 ..9.3....*..0...1..*..7.5.. ........3.0.......6.3......
output:
10
result:
ok 1 number(s): "10"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 25 .........+............... .......*.........-....... .*......8....+.........+. 6....*.....*...-.....-..4 ...*..3...1.1.7.4..*..6.. ..8.7.............1.1....
output:
8069
result:
ok 1 number(s): "8069"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
6 15 .....+......... .+.....+....... 6..-..3..+..... ..7.7...4..-... ..........1..-. ............8.1
output:
7
result:
ok 1 number(s): "7"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
10 37 .*................................... 5......*............................. ...*.......-......................... ..4..-...-...........-............... ....7.8.0.6........*...............+. ...............-....1..+............0 .............*...+....8......*....... ............0.7.0.4......*.....
output:
-3120
result:
ok 1 number(s): "-3120"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8 37 .......-............................. .*.................+................. 4....+...........*...*............... ...-..7......-....0.2............+... ..3.3....-.....-.............-.....-. ........9..-..9.6........*.....+..3.5 ..........8.8..........-...*..3.1.... ......................7.6.3.4...
output:
16
result:
ok 1 number(s): "16"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
8 37 .....................-............... .................*.................-. ...+...............+.........-......3 .*.....+..........4.5......-.....+... 0.4..*.........+.......*....0..*..8.. ....8.1....*....6.....1..*....4.8.... .........+...+..........7.1.......... ........6.5.7.4.................
output:
1251
result:
ok 1 number(s): "1251"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
8 37 .........................-........... ...........+.................*....... .........*.......+.........*.......-. .+........8..+.......-....2.0..+....0 0..*........8..-...*...-......6..+... ..3..-........0.1.2.9.8.1.......3.4.. ....0..+............................. ......1.5.......................
output:
-126
result:
ok 1 number(s): "-126"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
8 37 .....................+............... ...........-.............*........... .........-...+.........+...........+. .*........6.7..+......5.4....+......9 8......+......0..*.........-.....*... .....-..6.......0..*......4.9..-..2.. ...*..5...........9.5.........9.8.... ..0.9...........................
output:
49
result:
ok 1 number(s): "49"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
10 37 ...................................-. .............................*......5 ...+...........................-..... .*.....................+......4..*... 6.4....-.................-......1.0.. .....+.......+..........2..+......... ....4.7..-.......*........1.4........ ........2..-...+.....-.........
output:
-29
result:
ok 1 number(s): "-29"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
10 37 ...............................+..... .........................-.......-... .....................-.....+....1..+. .+.....................-..7..-....2.9 6..............*......0.7...7.8...... .......*...........*................. ...+.....+.......+..0................ ..5..+..8..+....1.1............
output:
-3
result:
ok 1 number(s): "-3"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
12 37 ...*................................. .-.................................+. 1.3..............................+..9 .............................*....3.. .......+.......................-..... .....*.....*..................9.6.... ....0.0..*.....*..................... ........5.3..*.....-...........
output:
-384
result:
ok 1 number(s): "-384"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
10 37 ...............................*..... ...........................*.....-... .-...........................-..4..+. 9....-......................2.8...7.6 ...-.................*............... ..8.6....-.............+............. .......+.......-......5..-........... ......8.7..*.......*....7.1....
output:
19980
result:
ok 1 number(s): "19980"
Test #37:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
12 37 .....+............................... ...*...............................+. .-..2..+............................7 0.3...2........................*..... ...........................*.....*... .......................+.....+..3.9.. .........-...............-..3.7...... ........1......*........1.6....
output:
-311037
result:
ok 1 number(s): "-311037"
Test #38:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
7 37 .................-................... ...........+.............-........... .........*...-.........*.......-..... ...+......5.8..-.....+..5..-.......-. .-.....-......4.2..*..0...3..*...-..0 9.7..+..0.........9.9.......8.5.6.1.. ....8.1..............................
output:
-386
result:
ok 1 number(s): "-386"
Test #39:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
7 37 .....................+............... .........+.....................-..... .+.............-.............*.....*. 7..*.......+.....-.....+......3..+..6 ..2....-..5..-..9..+..2..-......8.2.. .....+..8...6.4...2.8...4..-......... ....3.8...................3.5........
output:
-15
result:
ok 1 number(s): "-15"
Test #40:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
7 37 ...................*................. .............*.................-..... .........*.....-...........*.....+... .......-...-..8..+.....+.....+..9..+. ...-....6.9.0...0.3..+...-..4.9...1.6 .-...*..............5.1.5.3.......... 6.7.6.3..............................
output:
-99000
result:
ok 1 number(s): "-99000"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
7 37 ...............+..................... ...*.................*............... .-.........+.......-.......*......... 9.0....+.....+...-..5..*.....-....... .....+...-..5.1.6.3...4..-..3....*... ....8.7.4.4.............4.5....-...+. ..............................1.9.0.7
output:
661
result:
ok 1 number(s): "661"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
8 37 .....................*............... .......+.................*........... .....-...-.............*.....-....... .*....6.7..-..........3.6..+.....-... 9..+......7....*..........4.1..-...*. ..8.0........-...*............1.4.9.1 ............0.5.8..-................. ..................1.9...........
output:
118116
result:
ok 1 number(s): "118116"
Test #43:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 1 7
output:
7
result:
ok 1 number(s): "7"
Test #44:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
1 1 8
output:
8
result:
ok 1 number(s): "8"
Test #45:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 1 7
output:
7
result:
ok 1 number(s): "7"
Test #46:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 1 8
output:
8
result:
ok 1 number(s): "8"
Test #47:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1 3
output:
3
result:
ok 1 number(s): "3"
Test #48:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8 37 .......................*............. ...............*.............*....... .............*.......*.....*...*..... .......*......9..*....7..*..8.9..*... .....*...*......9..*....9.9.....9..*. .*....8.7..*......8.9.............9.7 9..*......9.9........................ ..7.8...........................
output:
308616905200472064
result:
ok 1 number(s): "308616905200472064"
Test #49:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
8 37 ...............................*..... .............*.....................*. .........*.......*...............*..7 .*.........*...*.............*..7.8.. 8....*....9.8.9.9....*........9...... ...*...*...........*.....*........... ..7.9.9.8.........7.8..*...*......... ......................7.8.9.9...
output:
189657576858451968
result:
ok 1 number(s): "189657576858451968"
Test #50:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
8 37 .............................*....... ...............*.................*... .*.....................*.......*...*. 9..*.............*.........*..8.9.8.8 ..7......*......7....*...*..8........ .......*.....*.....*..8.8.7.......... .....*..9..*..9...7.8................ ....7.8...9.7...................
output:
116552255737430016
result:
ok 1 number(s): "116552255737430016"
Test #51:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
9 37 .*................................... 8....................*............... ...................*...........*..... ...............*....9..*.........*... ...........*.....*....9..*......7..*. ...*.........*..9.7.....9..*......7.7 ..8....*....9.9...........8..*....... .....*...*..................9...
output:
240035370711478272
result:
ok 1 number(s): "240035370711478272"
Test #52:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
7 37 ...................*................. .......*.......................*..... .*.............*.....*.............*. 8....*.......*...*..7......*.....*..7 ...*..7....*..9.7.8....*.....*..9.7.. ..7.7....*..9.........9..*..8.7...... ........7.8.............9.9..........
output:
87841018911485952
result:
ok 1 number(s): "87841018911485952"