Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while (t--){
long long x1, x2;
int p1, p2;
cin >> x1 >> p1 >> x2 >> p2;
int mn = min(p1, p2);
p1 -= mn;
p2 -= mn;
if (p1 >= 7)
cout << ">" << endl;
else if (p2 >= 7)
cout << "<" << endl;
else{
for (int i = 0; i < p1; ++i) x1 *= 10;
for (int i = 0; i < p2; ++i) x2 *= 10;
if (x1 < x2)
cout << "<" << endl;
else if (x1 > x2)
cout << ">" << endl;
else
cout << "=" << endl;
}
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
int mn = *min_element(a.begin(), a.end());
for (int i = 0, k = 0; k < n / 2; ++i) if (a[i] != mn) {
cout << a[i] << ' ' << mn << '\n';
k += 1;
}
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
using li = long long;
int main() {
int t;
cin >> t;
while (t--) {
int n;
li h;
cin >> n >> h;
vector<li> a(n);
for (li &x : a) cin >> x;
li l = 1, r = 1e18;
while (l <= r) {
li m = (l + r) / 2;
li sum = m;
for (int i = 0; i < n - 1; ++i)
sum += min(m, a[i + 1] - a[i]);
if (sum < h) l = m + 1;
else r = m - 1;
}
cout << r + 1 << '\n';
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y) {
x += y;
if (x >= MOD) x -= MOD;
return x;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
vector<int> dp1(n + 2), dp2(n + 2);
dp1[0] = 1;
while (n--) {
int x;
scanf("%d", &x);
dp1[x + 1] = add(dp1[x + 1], dp1[x + 1]);
dp1[x + 1] = add(dp1[x + 1], dp1[x]);
if (x > 0) dp2[x - 1] = add(dp2[x - 1], dp2[x - 1]);
if (x > 0) dp2[x - 1] = add(dp2[x - 1], dp1[x - 1]);
dp2[x + 1] = add(dp2[x + 1], dp2[x + 1]);
}
int ans = 0;
for (int x : dp1) ans = add(ans, x);
for (int x : dp2) ans = add(ans, x);
printf("%d\n", add(ans, MOD - 1));
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
struct cell{
int x, y;
};
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int t;
cin >> t;
while (t--){
int n, m;
cin >> n >> m;
vector<string> s(n);
int lx = -1, ly = -1;
forn(i, n){
cin >> s[i];
forn(j, m) if (s[i][j] == 'L'){
lx = i;
ly = j;
}
}
auto in = [&](int x, int y){
return 0 <= x && x < n && 0 <= y && y < m;
};
vector<vector<int>> d(n, vector<int>(m, 0));
forn(x, n) forn(y, m) if (s[x][y] == '.'){
forn(i, 4){
int nx = x + dx[i];
int ny = y + dy[i];
d[x][y] += in(nx, ny) && s[nx][ny] != '#';
}
}
queue<cell> q;
vector<vector<char>> used(n, vector<char>(m, 0));
q.push({lx, ly});
used[lx][ly] = true;
while (!q.empty()){
int x = q.front().x;
int y = q.front().y;
q.pop();
forn(i, 4){
int nx = x + dx[i];
int ny = y + dy[i];
if (!in(nx, ny) || s[nx][ny] == '#' || used[nx][ny]) continue;
--d[nx][ny];
if (d[nx][ny] <= 1){
used[nx][ny] = true;
q.push({nx, ny});
}
}
}
forn(i, n){
forn(j, m) if (s[i][j] == '.' && used[i][j])
s[i][j] = '+';
cout << s[i] << "\n";
}
}
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sz(a) int((a).size())
const int MOD = 998244353;
struct Mint
{
int val;
bool operator==(const Mint& other)
{
return val == other.val;
}
Mint operator+(const Mint& other)
{
int res = val + other.val;
while(res >= MOD) res -= MOD;
while(res < 0) res += MOD;
return Mint(res);
}
Mint operator-(const Mint& other)
{
int res = val - other.val;
while(res >= MOD) res -= MOD;
while(res < 0) res += MOD;
return Mint(res);
}
Mint operator*(const Mint& other)
{
return Mint((val * 1ll * other.val) % MOD);
}
Mint pow(int y)
{
Mint z(1);
Mint x(val);
while(y > 0)
{
if(y % 2 == 1) z = z * x;
x = x * x;
y /= 2;
}
return z;
}
Mint operator/(const Mint& other)
{
return Mint(val) * Mint(other.val).pow(MOD - 2);
}
Mint() {
val = 0;
};
Mint(int x)
{
while(x >= MOD) x -= MOD;
while(x < 0) x += MOD;
val = x;
};
};
ostream& operator<<(ostream& out, const Mint& x)
{
return out << x.val;
}
const int g = 3;
const int LOGN = 19;
vector<Mint> w[LOGN];
vector<int> rv[LOGN];
void prepare() {
Mint wb = Mint(g).pow((MOD - 1) / (1 << LOGN));
forn(st, LOGN - 1) {
w[st].assign(1 << st, 1);
Mint bw = wb.pow(1 << (LOGN - st - 1));
Mint cw = 1;
forn(k, 1 << st) {
w[st][k] = cw;
cw = cw * bw;
}
}
forn(st, LOGN) {
rv[st].assign(1 << st, 0);
if (st == 0) {
rv[st][0] = 0;
continue;
}
int h = (1 << (st - 1));
forn(k, 1 << st)
rv[st][k] = (rv[st - 1][k & (h - 1)] << 1) | (k >= h);
}
}
void ntt(vector<Mint> &a, bool inv) {
int n = sz(a);
int ln = __builtin_ctz(n);
forn(i, n) {
int ni = rv[ln][i];
if (i < ni) swap(a[i], a[ni]);
}
forn(st, ln) {
int len = 1 << st;
for (int k = 0; k < n; k += (len << 1)) {
fore(pos, k, k + len){
Mint l = a[pos];
Mint r = a[pos + len] * w[st][pos - k];
a[pos] = l + r;
a[pos + len] = l - r;
}
}
}
if (inv) {
Mint rn = Mint(n).pow(MOD - 2);
forn(i, n) a[i] = a[i] * rn;
reverse(a.begin() + 1, a.end());
}
}
vector<Mint> mul(vector<Mint> a, vector<Mint> b) {
int cnt = 1 << (32 - __builtin_clz(sz(a) + sz(b) - 1));
a.resize(cnt);
b.resize(cnt);
ntt(a, false);
ntt(b, false);
vector<Mint> c(cnt);
forn(i, cnt) c[i] = a[i] * b[i];
ntt(c, true);
return c;
}
vector<Mint> norm(vector<Mint> a)
{
while(a.size() > 1 && a.back() == Mint(0))
a.pop_back();
return a;
}
const int N = 250043;
vector<int> G[N];
int d[N];
Mint fact[N * 2];
Mint rev[N * 2];
void dfs(int x, int p)
{
if(p != x) d[p]++;
for(auto y : G[x]) if(y != p) dfs(y, x);
}
Mint C(int n, int k)
{
return fact[n] * rev[k] * rev[n - k];
}
int main()
{
prepare();
fact[0] = Mint(1);
for(int i = 1; i < N * 2; i++) fact[i] = fact[i - 1] * i;
for(int i = 0; i < N * 2; i++) rev[i] = Mint(1) / fact[i];
int n;
scanf("%d", &n);
for(int i = 0; i < n - 1; i++)
{
int x, y;
scanf("%d %d", &x, &y);
--x;
--y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(0, 0);
vector<vector<Mint>> cur;
for(int i = 0; i < n; i++)
if(d[i] > 0)
cur.push_back(vector<Mint>({Mint(1), Mint(d[i])}));
while(cur.size() > 1)
{
vector<vector<Mint>> ncur;
for(int i = 0; i + 1 < cur.size(); i += 2)
ncur.push_back(norm(mul(cur[i], cur[i + 1])));
if(cur.size() % 2 == 1) ncur.push_back(cur.back());
cur = ncur;
}
Mint ans = 0;
for(int i = 0; i < cur[0].size(); i++)
{
if(i % 2 == 0) ans = ans + cur[0][i] * fact[n - i];
else ans = ans - cur[0][i] * fact[n - i];
}
cout << ans << endl;
}