답안 #321259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321259 2020-11-11T18:26:37 Z vukasinbabic06 Type Printer (IOI08_printer) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define inc(a,b,c) for(int a(b);a<=(c);a++)
#define dec(a,b,c) for(int a(b);a>=(c);a--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 25005;
const int MOD = 100003;
const int INF = 0x3f3f3f3f;

struct Word{ char c[25]; int id; };

int N, k, ans;
int len[MAX_N], val[MAX_N];
Word s[MAX_N];

// compare by first the length of common prefix with the longest word and then lexicographically
bool comp(Word a, Word b){
    return val[a.id] == val[b.id] ? lexicographical_compare(a.c + 1, a.c + len[a.id] + 1, b.c + 1, b.c + len[b.id] + 1) : val[a.id] < val[b.id];
}

int main(){
    freopen("type.in", "r", stdin);
    freopen("type.out", "w", stdout);
    
    scanf("%d", &N);
    inc(i, 1, N)
        scanf("%s", s[i].c + 1), s[i].id = i;
    inc(i, 1, N){
        len[i] = strlen(s[i].c + 1);
        if(len[i] > len[k])
            k = i;
    }
    
    inc(i, 1, N)
        inc(j, 1, len[i])
            if(s[i].c[j] == s[k].c[j])
                val[i]++;
            else
                break;

    sort(s + 1, s + N + 1, comp);
    inc(i, 1, N){
        int temp = 0;
        while(temp < min(len[s[i - 1].id], len[s[i].id]) && s[i - 1].c[temp + 1] == s[i].c[temp + 1])
            temp++;
        inc(j, 1, len[s[i - 1].id] - temp)
            ans++;
        inc(j, temp + 1, len[s[i].id])
            ans++;
        ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     freopen("type.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     freopen("type.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
printer.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%s", s[i].c + 1), s[i].id = i;
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -