Moderator: Board moderators

D.M.
New poster
Posts: 2
Joined: Mon Apr 21, 2003 10:46 am

Guyz, would u be so kind to send me the solution to this problem at ANY pr. language (but Pascal would be the best)? I've spent a few weeks trying to solve it; well, the local testing shows perfect results, but the online one always fails on the W/A. I really need it, 'case if I don't make it work - I'll be kicked out of my university. Plz help Tnx

Dukema
New poster
Posts: 3
Joined: Sun Jun 06, 2004 7:12 pm

### 680 - Can anybody send me some input please??? Wy WA????

I'm trying to solve the problem 680 but I allways get WA!! I had tried a lot of inputs and I thing the solution is correct for all of them!! If anybody could send me some input I would be very pleased to him!!
I send my code:

/* @JUDGE_ID: 43000WT 680 C++ */
#include <iostream>

using namespace std;

int main()
{
int Ntests;
int K,N;
int P;
cin >> Ntests;
for (int i=0;i<Ntests;i++){
cin >> K;
cin >> N;

int len_files[K],PF[K],acumulat[K],POS[K];
for(int j=0;j<K;j++)
cin >> len_files[j];
for(int j=0;j<K;j++){
cin >> PF[j];
POS[j] = PF[j];
if (j==0) acumulat[j]=0;
else acumulat[j] = len_files[j-1]+acumulat[j-1];
}

cin >> P;

if (N < K || P == 1){
cout << 0 << endl;
continue;
}
int suma_cost = 0;
int pos, next;
for (int j=0;j<P-1;j++){
pos = (j % K);
next = (pos+1) % K;

suma_cost += abs((POS[next]+acumulat[next])-(POS[pos]+acumulat[pos]));

/*cout << "POS[]=";
for (int w=0;w<K;w++)cout << POS[w] << ",";
cout << endl;
cout << "len_files[pos]: " << len_files[pos] << endl;
cout << "pos: " << pos << " next: " << next << endl <<
"POS[next]: " << POS[next] << " acumulat[next]: " <<
acumulat[next] << " POS[pos]: " << POS[pos] << " acumulat[pos]: " <<
acumulat[pos] << endl << "suma_c: "<<suma_cost << endl;
*/

POS[pos] = (POS[pos]+1) % (len_files[pos]+1);
if (POS[pos]==0)POS[pos]++;
}
cout << suma_cost<<endl;

}
cin >> Ntests;
if (Ntests != -1) cout << "Error entrada"<<endl;

}
Let's rock!

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia
Hi,
I haven't test your code, but I have an input.
Have you consider for k=1 (only one file) ?
Try this input.

Input

Code: Select all

``1 5 5 5 2``
Output

Code: Select all

``4``
The output is not 0.

Hope this helps.

Anggakusuma

Dukema
New poster
Posts: 3
Joined: Sun Jun 06, 2004 7:12 pm
Thanks a lot!!! I hadn't thought about that input! I finally solved it! Thanks!
I have posted a similar problem about the #10476... If you could take a look...
Let's rock!

Nobrain
New poster
Posts: 2
Joined: Fri Sep 10, 2004 3:57 am
I feel kind of stupid now. I've been pulling my hair over this one for way too long, and I can't even find some example that breaks my code. =( The sample indata works just great, and so did the single-file example mentioned above.

Anyone care to help?

[java]import java.io.IOException;
import java.util.StringTokenizer;

class Main {

public static void main(String[] args) throws Exception {

Main main = new Main();
main.run();

}

InputTokenizer in;

public void run() throws Exception {

in = new InputTokenizer();
int runs = in.nextIntToken();
for (int i = 0; i < runs; ++i) {
solveOne();
}

if (in.nextIntToken() != -1) {
while (true) ;
}

}

private void solveOne() {
int k = in.nextIntToken();
int n = in.nextIntToken();

int[] l = new int[k];
for (int i = 0; i < k; ++i) {
l = in.nextIntToken();
}

int[] pf = new int[k];
for (int i = 0; i < k; ++i) {
pf = in.nextIntToken();
}

int p = in.nextIntToken();

System.out.println(solve(k, n, l, pf, p));
}

private int solve(int k, int n, int[] l, int[] pf, int p) {
int[] sp = new int[k];
sp[0] = 0;
for (int i = 1; i < k; ++i) {
sp = sp[i-1] + l[i-1];
}

int result = 0; // total movement length

int nfile = 0; // next file - 1
int cpos = sp[nfile] + pf[nfile] - 1; // current head position
while (p-- > 0) {
int newpos = sp[nfile] + pf[nfile] - 1; // pf[] is 1 ... l[]

int dist = Math.abs(newpos - cpos);
result += dist;

++pf[nfile];
if (pf[nfile] > l[nfile]) {
pf[nfile] = 1;
}

++nfile;
if (nfile > (k-1)) {
nfile = 0;
}

cpos = newpos;
}

return result;
}

}

class InputTokenizer {

StringBuffer input;

StringTokenizer st;

public InputTokenizer() throws IOException {
input = new StringBuffer();

while (c != -1) {
input.append((char) c);
}

String str = input.toString();
st = new StringTokenizer(str);

if (str.indexOf('.') != -1 || str.indexOf(',') != -1) {
while (true) ;
}
}

public InputTokenizer(String input) throws IOException {
st = new StringTokenizer(input);
}

public boolean hasMoreTokens() {
return st.hasMoreTokens();
}

public int nextIntToken() {
return Integer.parseInt(st.nextToken());
}

public String nextToken() {
return st.nextToken();
}

}[/java]