I wrote this post to help my friend , Iman Movahhedi , complete this one.
Round #40 was my first contest here in Codeforces and I feel I fell in love with CF just after that.

A-Translation: (C# code)
Many languages have built-in reverse() function for strings. we can reverse one of the strings and check if it's equal to the other one , or we can check it manually. I prefer the second.

B-Martian Dollar: (C# code)
Since number of days is very small (2 × 103) we can just iterate over all possibilities of buy-day and sell-day. This will take θ (n2) time which is OK.

The first letter of the input string can not be part of an "at" or a "dot" so we start from the second character. Greedily put "." wherever you reached "dot" and put "@" the first time you reached "at". This will take θ(n) time , where n is the length of input.

D-Pawn:
For each cell of the table store k + 1 values. Where ith value is the maximum number of peas the pawn can take while he is at that cell and this number mod k + 1 is i.
This makes a O(n2 × m × k) dynamic programming which fits perfectly in the time.

E-3-cycles: (C++ code)
The road map with most edges is a complete bipartite graph with equal number of vertices on each side. (Prove it by yourself :D ). We can make such a graph by putting the first vertices on one side and the other on the other side.For sure , number of edges is .

• +21

 » 9 years ago, # |   0 To help understand the proof for E, check this comment http://www.codeforces.com/blog/entry/843#comment-13876
 » 7 years ago, # | ← Rev. 4 →   -26 thanks
 » 7 years ago, # | ← Rev. 2 →   0 I think problem D can be solved in O(nmk), see code.
•  » » 7 years ago, # ^ |   0 you mean D :)
•  » » » 7 years ago, # ^ |   0 Thanks!
 » 3 years ago, # |   0
»
2 years ago, # |
-11

include

using namespace std;

int main() { string a,b; int c; cin>>a; cin>>b; for(int i = 0 ; i<a.length(); i++) { if(a[i] == b[((b.length()) -1 — (i))]) { c = 1; } else { c = 0; } }

if(c)
{
cout<<"YES";
}
else
{
cout<<"NO";
}

return 0;

}

•  » » 2 years ago, # ^ |   -11 can someone tell why is it not working
•  » » » 2 years ago, # ^ |   -8 it is A question
•  » » » » 2 years ago, # ^ | ← Rev. 4 →   -8 .
 » 10 months ago, # |   0 question — A(Translation) for me Wrong answer on test 32...but i don't know why.... i'm not use any built in functions...