Submission #32561129


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> 
int SIZE(const T (&t)[N])
{ 
    return N; 
} 
template<typename T> 
int SIZE(const T &t)
{ 
    return t.size(); 
} 
string to_string(const string s, int x1=0, int x2=1e9)
{ 
    return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; 
} 
string to_string(const char* s) 
{ 
    return to_string((string) s); 
} 
string to_string(const bool b) 
{ 
    return (b ? "true" : "false"); 
} 
string to_string(const char c)
{ 
    return string({c}); 
} 
template<size_t N> 
string to_string(const bitset<N> &b, int x1=0, int x2=1e9)
{ 
    string t = ""; 
    for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__)
    { 
        t += b[__iii__] + '0'; 
    } 
    return '"' + t + '"'; 
} 
template <typename A, typename... C> 
string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); 
int l_v_l_v_l = 0, t_a_b_s = 0; 
template <typename A, typename B> 
string to_string(const pair<A, B> &p) 
{ 
    l_v_l_v_l++; 
    string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; 
    return res; 
} 
template <typename A, typename... C> 
string to_string(const A (&v), int x1, int x2, C... coords) 
{ 
    int rnk = rank<A>::value; string tab(t_a_b_s, ' '); 
    string res = ""; 
    bool first = true; 
    if(l_v_l_v_l == 0) 
        res += n_l; 
   res += tab + "["; 
   x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); 
   auto l = begin(v); 
   advance(l, x1); 
   auto r = l; 
   advance(r, (x2-x1) + (x2 < SIZE(v))); 
   for (auto e = l; e != r; e = next(e)) 
   { 
        if (!first)
        { 
            res += ", "; 
        } 
        first = false; 
        l_v_l_v_l++; 
        if(e != l)
        { 
            if(rnk > 1) 
            {
                 res += n_l; 
                 t_a_b_s = l_v_l_v_l; 
            }; 
       } 
       else{
        t_a_b_s = 0; 
      } 
      res += to_string(*e, coords...); 
      l_v_l_v_l--; 
    } 
    res += "]"; 
    if(l_v_l_v_l == 0) 
        res += n_l; 
    return res; 
} 
void dbgm(){;} 
template<typename Heads, typename... Tails> 
void dbgm(Heads H, Tails... T)
{ 
    cout << to_string(H) << " | "; dbgm(T...); 
} 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
void prepare(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    // #endif 
}
void solve(){
    int n;
    cin>>n;
    vector<long long>frus(n+1);
    vector<int>x(n+1);
    vector<long long>c(n+1);
    for(int i=1;i<=n;i++)
        cin>>x[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    for(int i=1;i<=n;i++)
        frus[x[i]]+=c[i];
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq;
    for(int i=1;i<=n;i++)
        pq.push({frus[i],i});
    vector<int>order(n+1);
    int i=1;
    while(pq.size()){
        auto p=pq.top();
        pq.pop();
        order[p.second]=i++;
    }
    //dbg(order);
    long long ans=0;
    for(int i=1;i<=n;i++){
        if(order[i]>order[x[i]])
            ans+=c[i];
    }
    cout<<ans;
}
int main() {
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}



Submission Info

Submission Time
Task E - Takahashi's Anguish
User Gogalvijay
Language C++ (GCC 9.2.1)
Score 0
Code Size 3610 Byte
Status WA
Exec Time 134 ms
Memory 11320 KiB

Compile Error

./Main.cpp: In function ‘std::string to_string(std::string, int, int)’:
./Main.cpp:18:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   18 |     return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"';
      |                    ~~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 3
WA × 14
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 03_many_cycles_00.txt, 03_many_cycles_01.txt, 04_large_cycle_00.txt, 04_large_cycle_01.txt, 05_largest_cycle_00.txt, 06_max_cycles_00.txt, 07_max_rho_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3600 KiB
00_sample_01.txt AC 2 ms 3552 KiB
01_small_00.txt WA 1 ms 3588 KiB
01_small_01.txt WA 2 ms 3488 KiB
01_small_02.txt WA 2 ms 3556 KiB
02_random_00.txt WA 132 ms 11188 KiB
02_random_01.txt WA 128 ms 11204 KiB
02_random_02.txt WA 129 ms 11280 KiB
02_random_03.txt WA 129 ms 11188 KiB
02_random_04.txt WA 127 ms 11320 KiB
03_many_cycles_00.txt WA 130 ms 11236 KiB
03_many_cycles_01.txt WA 133 ms 11144 KiB
04_large_cycle_00.txt WA 134 ms 11276 KiB
04_large_cycle_01.txt WA 130 ms 11208 KiB
05_largest_cycle_00.txt WA 127 ms 11136 KiB
06_max_cycles_00.txt AC 131 ms 11184 KiB
07_max_rho_00.txt WA 128 ms 11204 KiB