Need help with 1345C

Revision en2, by qhung312, 2020-05-07 02:53:36

1345C - Hilbert's Hotel requires you to check if all (i + arr[i]) % n is distinct, so I did:

for (int i = 0; i < n; i++) {
  ll x;
  cin >> x;
  arr[i] = (i + x) % n;
  s.insert(arr[i]);
}
cout << ((s.size() == n) ? "YES" : "NO") << '\n';

This got WA on test 2, whereas if I change it to:

arr[i] = ((i + x) % n + n) % n;

This got AC. But aren't (i + x) % n and ((i + x) % n + n) % n the same thing?

Tags #number theory

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English qhung312 2020-05-07 02:53:36 0 (published)
en1 English qhung312 2020-05-07 02:52:27 460 Initial revision (saved to drafts)