头像

我是fw




离线:22小时前


最近来访(136)
用户头像
啊额
用户头像
HZAU-EDU
用户头像
Lapis
用户头像
yxcccx
用户头像
2010
用户头像
花似羡
用户头像
大智慧的益生菌
用户头像
锈渎
用户头像
空白.1
用户头像
.Zero
用户头像
俄罗斯刺沙蓬
用户头像
乘风破浪_93
用户头像
acwing_80501
用户头像
有人在卷我_是不是你
用户头像
gsea37
用户头像
谈何功过
用户头像
Backlight
用户头像
Pedestrian
用户头像
414sboy
用户头像
IN0vation

分享 课程

AcWing《Linux基础课》拼团优惠!https://www.acwing.com/activity/content/introduction/57/group_buy/118859/



活动打卡代码 AcWing 4799. 最远距离

我是fw
10天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
ll dp[N][2],dep[N];
VI<int> t[N];
void solve() {
    std::cin >> n >> m;
    rep(i,1,m){
        int x,y;
        std::cin >> x >> y;
        t[x].push_back(y);
        t[y].push_back(x);
    }
    ll res = 0;
    std::function< void (int ,int)> dfs = [&](int u,int p){
        dep[u] = 1;ll mx1 = -1,mx2 = -1;
        for(auto v : t[u]) {
            if (v == p) continue;
            dfs(v, u);
            dep[u] = std::max(dep[v] + 1,dep[u]);
            if (dep[v] + 1> mx1)
                mx2 = mx1, mx1 = dep[v] + 1;
            else if (dep[v] + 1> mx2)
                mx2 = dep[v] + 1;
        }
        if(mx1 >= 0 && mx2 >= 0)
        res = std::max(res, mx1 + mx2 - 2);
        else if(mx1 >= 0)
        res = std::max(res,mx1 - 1);
        else
          res = std::max(res,0ll);
        //std::cout << mx1 << " " << mx2 << endl;
    };
    dfs(1,0);
    // for(int i = 1; i <= n; i ++)
    //     std::cout << dep[i] << " \n"[i == n];
    std::cout << res << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4798. 打怪兽

我是fw
10天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
void solve() {
    std::cin >> n >> m;
    VI<ll> a(n + 1);
    rep(i,1,n){
        std::cin >> a[i];
    }
    int l = 1, r = n;
    auto ck = [&](int x){
        VI<ll> b(x + 1);
        rep(i,1,x){
            b[i] = a[i];
        }
        std::sort(all(b));
        ll res = 0;
        if (x % 2 == 0){
            for(int i = 2; i <= x; i += 2)
                res += b[i];
        }
        else {
            for (int i = 1; i <= x; i += 2) {
                res += b[i];
            }
        }
       // std::cout << x << " " << res << endl;
        return res <= m;
    };
    while (l < r){
        int mid = l + r + 1 >> 1;
       // std::cout << l << " " << r << endl;
        if (ck(mid))
            l = mid;
        else
            r = mid - 1;
    }
    std::cout << r << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4729. 解密

我是fw
12天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
void solve() {
    ll a,b,d,e;
    std::cin >> n >> e >> d;
    a = n - e * d + 2;
    b = n;//std::cout << a << " " << b << endl;
    if (a > 1e9){
        if (a % 2){
            std::cout << "NO" << endl;
            return;
        }
        if (a / 2 * a / 2 != n){
            std::cout << "NO" << endl;
            return;
        }
        std::cout << a / 2 << " " << a / 2 << endl;;
        return;
    }

    ll c = a * a,cc = 4ll * b;
    if (c < cc ){
        std::cout << "NO" << endl;
        return;
    }
    ll qu = (ll)sqrtl(a * a - 4 * b);
    if (qu * qu != a * a - 4 * b){
        std::cout << "NO" << endl;
        return;
    }
    ll p = a + (ll)sqrtl(a * a - 4 * b);
    ll q = a - (ll)sqrtl(a * a - 4 * b);
    p /= 2, q /= 2;
    if (p > q)
        std::swap(p,q);
    std::cout << p << " " << q << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4728. 乘方

我是fw
13天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k,dp[N];
void solve() {
    ll a,b;
    std::cin >> a >> b;
    if (a == 1){
        std::cout << 1 << endl;
        return;
    }
    ll x = 1;
    rep(i,1, std::min(31ll,b)){
        x *= a;
        if (x > 1e9){
            std::cout << -1 << endl;
            return;
        }
    }
    std::cout << x << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 3422. 左孩子右兄弟

我是fw
14天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k,dp[N];
VI<int> t[N];
void solve() {
    std::cin >> n;
    rep(i,2,n){
        int x;
        std::cin >> x;
        t[x].push_back(i);
    }
    std::function<void (int )> dfs = [&](int u){
        int other = sz(t[u]) - 1;
        for(auto v : t[u]){
            dfs(v);
            dp[u] = std::max(dp[u],dp[v] + other + 1);
        }
    };
    dfs(1);
    std::cout << dp[1] << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}



我是fw
14天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k,l[N],r[N],id[N];
VI<int> t[N];
int g[500][500],f[2023][2023];
PII fc[N];
void solve() {
    ll L,S;
    std::cin >> n >> L >> S;
    //VI<PII> fc(n + 1);
    rep(i,1,n){
        ll x,y;
        std::cin >> x >> y;
        //f[x][y] = 1;
        fc[i] = mp(x,y);
    }
    rep(i,0,S){
        rep(j,0,S){
            int x;
            std::cin >> x;
            g[S - i][j] = x;
        }
    }
    std::set<PII> s;
    int q = 0;
    rep(x,0,S){
        rep(y,0,S){
            if (g[x][y] == 1)
                s.insert(mp(x + 1,y + 1)),q ++;
        }
    }
    ll res = 0;
    rep(i,1,n){
        auto t = s;
        int x = fc[i].x,y = fc[i].y;
        if (x + S > L || y + S > L)
            continue;
        bool ok = true;
        int bc = 0;
        rep(j,1,n){
            int a = fc[j].x,b = fc[j].y;
            int da = a - x + 1,dc = b - y + 1;
            if (da < 0 || dc < 0){
                //ok = false;
                continue;
            }
            if (t.count(mp(da,dc)))
                t.erase(mp(da,dc)),bc ++;
            else{
                if (da <= S + 1&& dc <= S + 1&& da > 0 && dc > 0){
                    ok = false;
                    break;
                }
            }
            //std::cout << j << " " << sz(t) << endl;
        }
        if (sz(t))
            ok = false;
        //std::cout << i << " " <<bc << endl;
        if (ok && bc == q)
            res ++;
    }
    std::cout << res << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4455. 出行计划

我是fw
17天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 5e5 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
ll dp[N];
void solve() {
    std::cin >> n >> m >> k;
    VI<int> s(1e6 + 1),T(n + 1);
    std::map<ll,int> hs;
    rep(i,1,n){
        int t,c;
        std::cin >> t >> c;
        T[i] = t;
        s[std::max(0ll,t - c - k + 1)] ++,s[std::max(0ll,t - k) + 1] --;
    }
    VI<int> ans(n + 1);
    rep(i,1,N){
        s[i] = s[i - 1] + s[i];
    }
    rep(i,1,m){
        int q;
        std::cin >> q;
        std::cout << s[q] << endl;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4794. 健身

我是fw
17天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 1e4 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
ll dp[N];
void solve() {
    std::cin >> n;
    VI<ll> a(n + 1);
    ll x = 0, y = 0, z = 0;
    rep(i,1,n)std::cin >> a[i];
    std::map<int,std::string > hs;
    hs[1] = "chest";
    hs[2] = "biceps";
    hs[3] = "back";
    rep(i,1,n){
        if (i % 3 == 1)
            x += a[i];
        else if (i % 3 == 2)
            y += a[i];
        else
            z += a[i];
    }
    ll c = std::max({x,y,z}),id;
    //std::cout << x << " " << y << " " << z << endl;
    if (c == x)
        id = 1;
    else if (c == y)
        id = 2;
    else
        id = 3;
    std::cout << hs[id] << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}


活动打卡代码 AcWing 4795. 安全区域

我是fw
17天前
#include <bits/stdc++.h>
//tle
using ll = long long;

const long long N = 1e4 + 10, P = 998244353, inf = (1ll << 60) - 1;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef std::pair<ll, ll> PII;
typedef std::pair<int, double> PID;
typedef std::pair<double, double> PDD;
#define endl '\n'
#define x first
#define y second
//#define db long double
#define db double
#define VI std::vector
#define lg2(x) log2(x)
#define PI acosl(-1)
#define mp(x, y) std::make_pair(x, y)
#define debug(c, a) std::cout << c << " : " << a << endl;
#define pb(x) push_back(x)
#define bt(x) (1ll << (x))
#define sz(x) (int) (x.size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rap(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (ll i = b; i >= a; i--)
#define all(x) x.begin() + 1, x.end()
#define pt(x) std::cout << std::fixed << std::setprecision(12) << x << " ";
//std::mt19937_64 mrnd(std::random_device{}());
ll n, m, k;
ll dp[N];
void solve() {
    std::cin >> n >> m;
    std::map<int,int> x,y;
    ll col = 0,lin = 0,sum = n * n;
  //  std::cout << n * n -
    while (m --){
        int x1,y1;
        std::cin >> x1 >> y1;
        if (!x.count(x1)) col ++;
        if (!y.count(y1)) lin ++;
        x[x1]++,y[y1]++;
        //std::cout << col << " " << lin << endl;
        std::cout << sum - (col + lin) * n + col * lin << " \n"[m == 0];
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _ = 1;
    //std::cin >> _;
    while (_--){
        solve();
    }
    return 0;
}