QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240062#5487. Movie Nightkareemsakkary#WA 0ms3636kbC++142.2kb2023-11-05 10:33:082023-11-05 10:33:08

Judging History

你现在查看的是最新测评结果

  • [2023-11-05 10:33:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2023-11-05 10:33:08]
  • 提交

answer

    #include <bits/stdc++.h>

    #define all(x) (x).begin(), (x).end()
    #define endl '\n'
    #define yes cout << "YES\n";
    #define no cout << "NO\n";
    #define fr(n) for(ll i = 0 ; i < n ; i++)
    #define frj(n) for(ll j = 0 ; j < n ; j++)
    #define ll long long
    #define files    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #define Ksakkary ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    const ll mod = 1e9 + 7;

    using namespace std;


    ll gcd(ll a, ll b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    ll mult(ll a, ll b) {
        return ((a % mod) * (b % mod)) % mod;
    }

    ll add(ll a, ll b) {
        return ((a % mod) + (b % mod)) % mod;
    }

    ll subtract(ll a, ll b) {
        return ((a % mod) - (b % mod) + (2 * mod)) % mod;
    }

    const unsigned ll N = 2e6 + 5;

    int knightX[] = {-2, -2, 2, 2, 1, 1, -1, -1};
    int knighty[] = {-1, 1, -1, 1, -2, 2, -2, 2};

    int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
    int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
    char di[] = {'D', 'L', 'U', 'R'};
    ll fastPow(ll a, ll b){
        ll res = 1;
        while (b > 0)
        {
            if(b&1)
                res = mult(a, res);

            a = mult(a, a);
            b/=2;
        }
        return res;
    }
    ll n , m , ti;
    vector<int> y , vis;
    ll ans  = 0;
    ll dfs(int node , int depth){
        if(vis[node]){
            return vis[node];
        }
        vis[node] = depth;
        return dfs(y[node],depth+1);
    }
    void solve() {
        cin >> n;
        y = vis = vector<int> (n);
        fr(n){
            cin >> y[i];
            y[i]--;
        }
        fr(n){
            if(!vis[i]) {
                ans = add(ans, dfs(i, 1));
                if (i != 0)
                    ans = (mult(ans, ans + 1) * fastPow(2,mod-2))%mod;
            }
        }
        cout << ans << endl;
    }

    int main() {
        Ksakkary
    #ifndef ONLINE_JUDGE
        files
    #endif
        // sieve();
        ll t = 1;
    //    cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

4
2
3
4
3

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5
2
3
1
5
4

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3636kb

input:

6
2
4
2
6
1
3

output:

6

result:

wrong answer 1st lines differ - expected: '3', found: '6'