求调,悬关,悬RP
  • 板块题目总版
  • 楼主ZhuYF1029
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/1/24 16:03
  • 上次更新2024/1/24 18:33:27
查看原帖
求调,悬关,悬RP
802655
ZhuYF1029楼主2024/1/24 16:03

P7005

求调

ICU传送门

我的 2++ hours 错误代码

// Code by HackerZhuYifan!
#include<bits/stdc++.h>
#define int long long
#define mod 998244353
#define inf 9187201950435737471
const int maxn=5e4+10;
using namespace std;
string bg="('@')";
int n,dp[maxn],pre[maxn],tot,ans,mx;
string s,fa,son;
map<string,int> f;
void dg(int x){
    if(x==0) return;
    dg(pre[x]);
    cout << x << " ";
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    	freopen("code.txt","r",stdin);
    #endif
	cin >> n;
    while(cin >> s){
        if(s.size()>2 && s[0]=='@' && s[s.size()-1]==':'){
            dp[++tot]=1;
            fa=s.substr(1,s.size()-2);
            if(f.find(fa)==f.end()) f[fa]=tot;
            if(ans<dp[tot]) ans=dp[tot],mx=tot;
            continue;
        }else if(s.size()>1 && s[0]=='@'){
            son=s.substr(1,s.size()-1);
        }else{
            continue;
        }
        if(fa==son){
            continue;
        }
        if(f.find(son)!=f.end() && dp[tot]<dp[f[son]]+1){
            dp[tot]=dp[f[son]]+1;
            pre[tot]=f[son];
        }
        if(f.find(fa)==f.end() || dp[tot]>dp[f[fa]]) f[fa]=tot;
        if(dp[tot]>ans) ans=dp[tot],mx=tot;
    }
    cout << ans << endl;
    dg(mx);
    return 0;
}

不用看到底是句柄开头是('@')还是只有@,都过不了

2024/1/24 16:03
加载中...