your code does found the optimal solution though it sorts by ranks.
Eg:
your output
1
3 3
Case #1: 4
6 2
5 2
4 1
3 1
optimal solution would be
1
3 3
Case #1: 3
2 5
2 2
3 5



On Monday, April 20, 2020 at 10:08:09 PM UTC+5:30, Atif Hussain wrote:
>
> 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 google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/03435576-42ab-4fd4-a273-1783614e53d2%40googlegroups.com.

Reply via email to