Task: | Algorithm |
Sender: | JiK |
Submission time: | 2018-10-04 18:26:03 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | ACCEPTED | 0.05 s | details |
#7 | ACCEPTED | 0.08 s | details |
#8 | ACCEPTED | 0.09 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.02 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.07 s | details |
#13 | ACCEPTED | 0.04 s | details |
#14 | ACCEPTED | 0.08 s | details |
#15 | ACCEPTED | 0.07 s | details |
#16 | ACCEPTED | 0.08 s | details |
#17 | ACCEPTED | 0.05 s | details |
#18 | ACCEPTED | 0.10 s | details |
#19 | ACCEPTED | 0.09 s | details |
#20 | ACCEPTED | 0.10 s | details |
Compiler report
In file included from /usr/include/c++/7/cassert:44:0, from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33, from input/code.cpp:1: input/code.cpp: In function 'long int ftest(std::vector<long int>&, std::vector<long int>&, int)': input/code.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] assert( a.size() == n ); ~~~~~~~~~^~~~ input/code.cpp:57:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] assert( b.size() == n ); ~~~~~~~~~^~~~ input/code.cpp:78:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i=0; i<aod.size(); i++) { ~^~~~~~~~~~~ input/code.cpp:81:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i=0; i<aev.size(); i++) { ~^~~~~~~~~~~
Code
#include <bits/stdc++.h> using namespace std; typedef bitset<20> bs; typedef int64_t ll; typedef pair<ll,ll> PLL; typedef pair<int, pair<int,int>> PQ; // [a][b][t] start a end b start at time t int vals[100][100][501]; long f(int i, int j, vector<ll> & a, vector<ll> & b, int n) { if (i >= n) return 0; swap(a[i],a[j]); long r = a[i]*b[i] + f(i+1,i+1,b,a,n); swap(a[i],a[j]); if (j < n-2) { r = min(r, f(i,j+2,a,b,n)); } return r; } int INF = 1<<30; long fn(int i, int j, vector<ll> & a, vector<ll> & b, int n) { if (i >= n) return 0; swap(a[i],a[j]); long r = a[i]*b[i] + f(i+1,i+1,b,a,n); swap(a[i],a[j]); if (j==i) { for (j=i+2; j<n-2; j+=2) { swap(a[i],a[j]); r = min(r, a[i]*b[i] + f(i+1,i+1,b,a,n)); swap(a[i],a[j]); } } return r; } long ftest(vector<ll> & a, vector<ll> & b, int n) { vector<ll> aev; vector<ll> bev; vector<ll> aod; vector<ll> bod; assert( a.size() == n ); assert( b.size() == n ); for (int i=0; i<n; i++) { if (i&1) { //cout << i << " " << a.size() << endl; //cout << a[i] << " " << b[i] << endl; aod.push_back(a[i]); bod.push_back(b[i]); } else { aev.push_back(a[i]); bev.push_back(b[i]); } } sort(aod.begin(), aod.end()); sort(bod.begin(), bod.end(), greater<ll>()); sort(aev.begin(), aev.end()); sort(bev.begin(), bev.end(), greater<ll>()); ll res = 0; for (int i=0; i<aod.size(); i++) { res += aod[i] * bod[i]; } for (int i=0; i<aev.size(); i++) { res += aev[i] * bev[i]; } return res; } int main() { cout << std::setprecision(15); int n; cin >> n; vector<ll> a (n); vector<ll> b(n); for (int ai=0; ai<n; ai++) { cin >> a[ai]; } for (int ai=0; ai<n; ai++) { cin >> b[ai]; } // cout << fn(0,0,a,b,n) << endl;; cout << ftest(a,b,n) << endl;; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 32746 15006 |
correct output |
---|
491386476 |
user output |
---|
491386476 |
Test 2
Verdict: ACCEPTED
input |
---|
2 84132 85719 1642 54698 |
correct output |
---|
4826802606 |
user output |
---|
4826802606 |
Test 3
Verdict: ACCEPTED
input |
---|
6 41330 28426 25487 59476 70096 ... |
correct output |
---|
10630121150 |
user output |
---|
10630121150 |
Test 4
Verdict: ACCEPTED
input |
---|
6 15850 37471 96913 85418 33217 ... |
correct output |
---|
23737628192 |
user output |
---|
23737628192 |
Test 5
Verdict: ACCEPTED
input |
---|
11009 38035 60240 149 38250 70808 37... |
correct output |
---|
18304875959716 |
user output |
---|
18304875959716 |
Test 6
Verdict: ACCEPTED
input |
---|
29086 93819 2356 60430 158 44857 321... |
correct output |
---|
48968537132096 |
user output |
---|
48968537132096 |
Test 7
Verdict: ACCEPTED
input |
---|
75579 10591 41089 16531 41698 82003 ... |
correct output |
---|
125660040823300 |
user output |
---|
125660040823300 |
Test 8
Verdict: ACCEPTED
input |
---|
92599 42887 18515 77443 87957 53300 ... |
correct output |
---|
153117286209079 |
user output |
---|
153117286209079 |
Test 9
Verdict: ACCEPTED
input |
---|
12750 68333 40184 67292 63619 68541 ... |
correct output |
---|
21126603213442 |
user output |
---|
21126603213442 |
Test 10
Verdict: ACCEPTED
input |
---|
269 76556 93378 42791 50627 59426 ... |
correct output |
---|
466237829689 |
user output |
---|
466237829689 |
Test 11
Verdict: ACCEPTED
input |
---|
50819 41607 66320 69389 34917 96388 ... |
correct output |
---|
84940594307484 |
user output |
---|
84940594307484 |
Test 12
Verdict: ACCEPTED
input |
---|
56979 71780 75400 45136 60747 21539 ... |
correct output |
---|
95121604772805 |
user output |
---|
95121604772805 |
Test 13
Verdict: ACCEPTED
input |
---|
20096 36777 2257 40753 43704 59142 7... |
correct output |
---|
33847325368941 |
user output |
---|
33847325368941 |
Test 14
Verdict: ACCEPTED
input |
---|
82635 75904 49381 1260 79433 46653 2... |
correct output |
---|
138550776766607 |
user output |
---|
138550776766607 |
Test 15
Verdict: ACCEPTED
input |
---|
66218 70872 77635 90599 44971 61510 ... |
correct output |
---|
109807323471352 |
user output |
---|
109807323471352 |
Test 16
Verdict: ACCEPTED
input |
---|
74026 35777 82054 33603 5406 99848 8... |
correct output |
---|
123730965128574 |
user output |
---|
123730965128574 |
Test 17
Verdict: ACCEPTED
input |
---|
37200 86113 44283 11697 85369 77185 ... |
correct output |
---|
62498517042431 |
user output |
---|
62498517042431 |
Test 18
Verdict: ACCEPTED
input |
---|
100000 60221 73651 92556 11716 14965 ... |
correct output |
---|
166395583803984 |
user output |
---|
166395583803984 |
Test 19
Verdict: ACCEPTED
input |
---|
100000 25285 56218 72142 75382 30325 ... |
correct output |
---|
165945144240022 |
user output |
---|
165945144240022 |
Test 20
Verdict: ACCEPTED
input |
---|
100000 75969 51394 23093 7680 67765 8... |
correct output |
---|
166993204374124 |
user output |
---|
166993204374124 |