Hi,
For Google CodeJam 2020 Round 1B - 3.JoinTheRanks - below was my C++
submission, which gave WA for hidden inputs.
https://codingcompetitions.withgoogle.com/codejam/round/000000000019fef2/00000000002d5b64
Please help identify my error - in code, or input where it fails.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int testcases; cin >> testcases;
for (int t = 1; t <= testcases; t++) {
int R, S; cin >> R >> S;
vector<pair<int, int>> deck(R*S);
for (int j = 0; j < S; j++)
for (int i = 0; i < R; i++)
deck[i + R * j].first = i + 1,
deck[i + R * j].second = j + 1;
vector<pair<int, int>> moves;
int till, from;
for (till = R * S - 1; till >= 0; till--) {
int toR = (till / S) + 1;
if (deck[till].first==toR) continue;
for (from = till - 1; deck[from].first != toR; from--);
// deck[from].first = toR != deck[till].first
from++; till++;
moves.push_back(make_pair(from, till-from));
vector<pair<int, int>> A(deck.begin(), deck.begin() + from);
vector<pair<int, int>> B(deck.begin()+from, deck.begin() +
till);
deck.erase(deck.begin() + from, deck.begin() + till);
deck.insert(deck.begin(), B.begin(), B.end());
}
cout << "Case #" << t << ": " << moves.size() << endl;
for (int i = 0; i < moves.size(); i++)
cout << moves[i].first << " " << moves[i].second << endl;
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/c184071e-578b-4624-ade5-42129d013737%40googlegroups.com.