답안 #474097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474097 2021-09-16T21:33:48 Z ShahdMohamed Paths (BOI18_paths) C++17
100 / 100
907 ms 116948 KB
///LW M4 ACC HAZ3L GAMED
///YARAB WALA...I MEAN YARAB ACC
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
const ll mod = (ll) 1e9 + 7;
using namespace std;
ll n,m,k;
vector<ll>c;
vector<string>s;
vector<vector<ll>>v(300001);
vector<vector<ll>>dp(300001,vector<ll>(34,-1));
void yap()
{
    s.push_back("0");
    s.push_back("1");
    s.push_back("2");
    s.push_back("3");
    s.push_back("4");
    s.push_back("5");
    s.push_back("12");
    s.push_back("13");
    s.push_back("14");
    s.push_back("15");
    s.push_back("23");
    s.push_back("24");
    s.push_back("25");
    s.push_back("34");
    s.push_back("35");
    s.push_back("45");
    s.push_back("123");
    s.push_back("124");
    s.push_back("125");
    s.push_back("134");
    s.push_back("135");
    s.push_back("145");
    s.push_back("234");
    s.push_back("235");
    s.push_back("245");
    s.push_back("345");
    s.push_back("1234");
    s.push_back("1235");
    s.push_back("1245");
    s.push_back("1345");
    s.push_back("2345");
    s.push_back("12345");
}
ll num(string st)
{
    for (ll i=1; i<=31; i++)
    {
        if (s[i]==st)
            return i;
    }
}
ll solve(ll node,ll nm)
{
    string st=s[nm];
    if (dp[node][nm]!=-1)
        return dp[node][nm];
    ll ans=1;
    for (auto ch:v[node])
    {
        string f=to_string(c[ch]);
        ll a=st.find(f[0]);
        if (a<0 or a>=st.size())
        {
            string fans=st;
            fans+=f;
            sort(fans.begin(),fans.end());
            ll g=num(fans);
            ans+=solve(ch,g);
        }
    }
    return dp[node][nm]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    yap();
    cin>>n>>m>>k;
    c.resize(n+1);
    for (ll i=1; i<=n; i++)
    {
        cin>>c[i];
    }
    for (ll i=0; i<m; i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll sum=0;
    for (ll i=1; i<=n; i++)
    {
        string f=to_string(c[i]);
        ll g=num(f);
        sum+=solve(i,g);
        sum--;
    }
    cout<<sum<<endl;

    return 0;
}

Compilation message

paths.cpp: In function 'long long int solve(long long int, long long int)':
paths.cpp:66:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if (a<0 or a>=st.size())
      |                    ~^~~~~~~~~~~
paths.cpp: In function 'long long int num(std::string)':
paths.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 98840 KB Output is correct
2 Correct 145 ms 98924 KB Output is correct
3 Correct 137 ms 98904 KB Output is correct
4 Correct 136 ms 98928 KB Output is correct
5 Correct 140 ms 98908 KB Output is correct
6 Correct 141 ms 98932 KB Output is correct
7 Correct 140 ms 98860 KB Output is correct
8 Correct 138 ms 98872 KB Output is correct
9 Correct 138 ms 98856 KB Output is correct
10 Correct 138 ms 98916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 109124 KB Output is correct
2 Correct 335 ms 108356 KB Output is correct
3 Correct 730 ms 116292 KB Output is correct
4 Correct 349 ms 110756 KB Output is correct
5 Correct 260 ms 110544 KB Output is correct
6 Correct 592 ms 113456 KB Output is correct
7 Correct 711 ms 116284 KB Output is correct
8 Correct 670 ms 116828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 98840 KB Output is correct
2 Correct 145 ms 98924 KB Output is correct
3 Correct 137 ms 98904 KB Output is correct
4 Correct 136 ms 98928 KB Output is correct
5 Correct 140 ms 98908 KB Output is correct
6 Correct 141 ms 98932 KB Output is correct
7 Correct 140 ms 98860 KB Output is correct
8 Correct 138 ms 98872 KB Output is correct
9 Correct 138 ms 98856 KB Output is correct
10 Correct 138 ms 98916 KB Output is correct
11 Correct 364 ms 109124 KB Output is correct
12 Correct 335 ms 108356 KB Output is correct
13 Correct 730 ms 116292 KB Output is correct
14 Correct 349 ms 110756 KB Output is correct
15 Correct 260 ms 110544 KB Output is correct
16 Correct 592 ms 113456 KB Output is correct
17 Correct 711 ms 116284 KB Output is correct
18 Correct 670 ms 116828 KB Output is correct
19 Correct 354 ms 109024 KB Output is correct
20 Correct 322 ms 108176 KB Output is correct
21 Correct 755 ms 116276 KB Output is correct
22 Correct 332 ms 110580 KB Output is correct
23 Correct 256 ms 110672 KB Output is correct
24 Correct 600 ms 113600 KB Output is correct
25 Correct 720 ms 116292 KB Output is correct
26 Correct 688 ms 116948 KB Output is correct
27 Correct 497 ms 108336 KB Output is correct
28 Correct 569 ms 110532 KB Output is correct
29 Correct 907 ms 116292 KB Output is correct
30 Correct 893 ms 112848 KB Output is correct
31 Correct 901 ms 112944 KB Output is correct
32 Correct 901 ms 116292 KB Output is correct
33 Correct 140 ms 98996 KB Output is correct
34 Correct 138 ms 98836 KB Output is correct
35 Correct 145 ms 98916 KB Output is correct
36 Correct 141 ms 98888 KB Output is correct
37 Correct 139 ms 98860 KB Output is correct
38 Correct 138 ms 98832 KB Output is correct
39 Correct 138 ms 98928 KB Output is correct
40 Correct 141 ms 98872 KB Output is correct
41 Correct 139 ms 98884 KB Output is correct
42 Correct 137 ms 98868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 98824 KB Output is correct
2 Correct 379 ms 101836 KB Output is correct
3 Correct 198 ms 101768 KB Output is correct
4 Correct 294 ms 104504 KB Output is correct
5 Correct 252 ms 105060 KB Output is correct
6 Correct 422 ms 104608 KB Output is correct
7 Correct 255 ms 101872 KB Output is correct
8 Correct 326 ms 104488 KB Output is correct
9 Correct 294 ms 105008 KB Output is correct
10 Correct 317 ms 105136 KB Output is correct
11 Correct 430 ms 103100 KB Output is correct
12 Correct 337 ms 103912 KB Output is correct
13 Correct 395 ms 103496 KB Output is correct
14 Correct 399 ms 104644 KB Output is correct
15 Correct 337 ms 104676 KB Output is correct
16 Correct 140 ms 98972 KB Output is correct
17 Correct 138 ms 99036 KB Output is correct
18 Correct 137 ms 98916 KB Output is correct
19 Correct 140 ms 98836 KB Output is correct
20 Correct 143 ms 98980 KB Output is correct
21 Correct 138 ms 98852 KB Output is correct
22 Correct 137 ms 98884 KB Output is correct
23 Correct 139 ms 98920 KB Output is correct
24 Correct 141 ms 98820 KB Output is correct
25 Correct 138 ms 98892 KB Output is correct